samsonDzealot commited on
Commit
7e40f45
·
verified ·
1 Parent(s): a6e820e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py CHANGED
@@ -29,6 +29,80 @@ class BasicAgent:
29
  "get_files_task_id_tool": lambda task_id: get_files_task_id_tool(task_id),
30
  "image_processing_tool": lambda file_content: image_processing_tool(file_content)
31
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  def run_and_submit_all( profile: gr.OAuthProfile | None):
34
  """
 
29
  "get_files_task_id_tool": lambda task_id: get_files_task_id_tool(task_id),
30
  "image_processing_tool": lambda file_content: image_processing_tool(file_content)
31
  }
32
+
33
+ def web_search_tool(search_terms: str) -> str:
34
+ """
35
+ Retrieves information from the internet using DuckDuckGo Search and returns results in JSON format.
36
+
37
+ Args:
38
+ search_terms (str): The search query to look up.
39
+
40
+ Returns:
41
+ str: JSON string containing search results.
42
+
43
+ Example:
44
+ >>> web_search_tool("H. pylori trial NIH")
45
+ '{"results": [{"title": "H. pylori Trial", "snippet": "90 patients enrolled Jan-May 2018"}]}'
46
+ """
47
+ try:
48
+ with DDGS() as ddgs:
49
+ results = [r for r in ddgs.text(search_terms, max_results=3)]
50
+ return str({"results": results})
51
+ except Exception as e:
52
+ return str({"error": f"Search failed: {str(e)}"})
53
+
54
+ def decimal_approximation_tool(number: float, decimals: int = 1) -> float:
55
+ """
56
+ Adjusts a numerical answer to the specified number of decimal places.
57
+
58
+ Args:
59
+ number (float): The number to round.
60
+ decimals (int): Number of decimal places to round to (default is 1).
61
+
62
+ Returns:
63
+ float: The rounded number.
64
+
65
+ Example:
66
+ >>> decimal_approximation_tool(4.567, 1)
67
+ 4.6
68
+ """
69
+ return round(float(number), decimals)
70
+
71
+ def get_files_task_id_tool(task_id: str) -> str:
72
+ """
73
+ Downloads the file associated with the given task_id and returns its content as a string.
74
+
75
+ Args:
76
+ task_id (str): The ID of the task to fetch the file for.
77
+
78
+ Returns:
79
+ str: The file content as a string (e.g., text or image description).
80
+
81
+ Example:
82
+ >>> get_files_task_id_tool("task_1")
83
+ 'Nutrition facts: Calories 390, Butterfat 11%'
84
+ """
85
+ # Simulated API call to GET /files/{task_id}
86
+ if task_id == "task_1":
87
+ return "Nutrition facts: Calories 390, Butterfat 11%"
88
+ return f"No file found for task_id: {task_id}"
89
+
90
+ def image_processing_tool(file_content: str) -> str:
91
+ """
92
+ Processes an image file (or its description) and extracts relevant information as text.
93
+
94
+ Args:
95
+ file_content (str): The file content or description (e.g., from get_files_task_id_tool).
96
+
97
+ Returns:
98
+ str: Extracted text or description of the image.
99
+
100
+ Example:
101
+ >>> image_processing_tool("Nutrition facts: Calories 390, Butterfat 11%")
102
+ 'Calories: 390, Butterfat: 11%'
103
+ """
104
+ # Simulated image processing (e.g., OCR or description)
105
+ return f"Extracted: {file_content}"
106
 
107
  def run_and_submit_all( profile: gr.OAuthProfile | None):
108
  """