LamiaYT commited on
Commit
7cea8e1
·
1 Parent(s): fcf479d
Files changed (1) hide show
  1. app.py +18 -19
app.py CHANGED
@@ -34,8 +34,7 @@ def serper_search(query: str) -> str:
34
  return "Serper key missing, please set SERPER_API_KEY."
35
 
36
  # --- Other Tools (unchanged) ---
37
- from smolagents.tools import tool
38
- import os, requests
39
 
40
  @tool
41
  def serper_search(query: str) -> str:
@@ -43,10 +42,10 @@ def serper_search(query: str) -> str:
43
  Performs a Google search using the Serper API.
44
 
45
  Args:
46
- query (str): The search query to look up.
47
 
48
  Returns:
49
- str: A formatted string with search results or an error message.
50
  """
51
  api_key = os.getenv("SERPER_API_KEY")
52
  if not api_key:
@@ -66,17 +65,16 @@ def serper_search(query: str) -> str:
66
  return f"Error during search: {e}"
67
 
68
 
69
-
70
  @tool
71
  def wikipedia_search(query: str) -> str:
72
  """
73
- Search Wikipedia for a summary or basic search results.
74
 
75
  Args:
76
- query (str): The search term to look up on Wikipedia.
77
 
78
  Returns:
79
- str: A summary of the topic or a list of search result snippets.
80
  """
81
  try:
82
  url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + query.replace(" ", "_")
@@ -94,14 +92,14 @@ def wikipedia_search(query: str) -> str:
94
  @tool
95
  def text_processor(text: str, operation: str = "analyze") -> str:
96
  """
97
- Perform a text operation like reversing or analyzing a string.
98
 
99
  Args:
100
- text (str): The input string to process.
101
- operation (str): The operation to perform. Options: 'reverse', 'parse', 'analyze'.
102
 
103
  Returns:
104
- str: The result of the text processing.
105
  """
106
  if operation == "reverse":
107
  return text[::-1]
@@ -114,13 +112,13 @@ def text_processor(text: str, operation: str = "analyze") -> str:
114
  @tool
115
  def math_solver(problem: str) -> str:
116
  """
117
- Solve or explain a math-related problem in natural language.
118
 
119
  Args:
120
- problem (str): A math question or prompt.
121
 
122
  Returns:
123
- str: An explanation or analysis related to the math topic.
124
  """
125
  if "commutative" in problem.lower():
126
  return "Check examples a*b vs b*a; look for counterexamples."
@@ -130,14 +128,14 @@ def math_solver(problem: str) -> str:
130
  @tool
131
  def data_extractor(source: str, target: str) -> str:
132
  """
133
- Extract data elements from a text source based on the target keyword.
134
 
135
  Args:
136
- source (str): The raw input text to extract data from.
137
- target (str): The type of data to extract (e.g., 'botanical vegetables').
138
 
139
  Returns:
140
- str: A filtered list or extracted segment from the input.
141
  """
142
  if "botanical" in target.lower() and "vegetable" in source:
143
  items = [i.strip() for i in source.split(",")]
@@ -145,6 +143,7 @@ def data_extractor(source: str, target: str) -> str:
145
  return ", ".join(true_veg) or "No true vegetables found."
146
  return f"Extract {target} from source..."
147
 
 
148
  # --- Agent Setup ---
149
  class GAIAAgent:
150
  def __init__(self):
 
34
  return "Serper key missing, please set SERPER_API_KEY."
35
 
36
  # --- Other Tools (unchanged) ---
37
+
 
38
 
39
  @tool
40
  def serper_search(query: str) -> str:
 
42
  Performs a Google search using the Serper API.
43
 
44
  Args:
45
+ query (str): The search query string to look up.
46
 
47
  Returns:
48
+ str: A formatted string of search results or an error message.
49
  """
50
  api_key = os.getenv("SERPER_API_KEY")
51
  if not api_key:
 
65
  return f"Error during search: {e}"
66
 
67
 
 
68
  @tool
69
  def wikipedia_search(query: str) -> str:
70
  """
71
+ Searches Wikipedia and returns a summary or search results.
72
 
73
  Args:
74
+ query (str): The search query for the Wikipedia lookup.
75
 
76
  Returns:
77
+ str: A summary from Wikipedia or search result snippets.
78
  """
79
  try:
80
  url = "https://en.wikipedia.org/api/rest_v1/page/summary/" + query.replace(" ", "_")
 
92
  @tool
93
  def text_processor(text: str, operation: str = "analyze") -> str:
94
  """
95
+ Performs basic text operations such as reversing, parsing, or analyzing a string.
96
 
97
  Args:
98
+ text (str): The input text to process.
99
+ operation (str): The operation to perform. Options include 'reverse', 'parse', or 'analyze'.
100
 
101
  Returns:
102
+ str: The result of the specified text operation.
103
  """
104
  if operation == "reverse":
105
  return text[::-1]
 
112
  @tool
113
  def math_solver(problem: str) -> str:
114
  """
115
+ Solves or explains a math-related problem in natural language.
116
 
117
  Args:
118
+ problem (str): A math-related question, formula, or problem description.
119
 
120
  Returns:
121
+ str: An explanation, answer, or analysis of the math problem.
122
  """
123
  if "commutative" in problem.lower():
124
  return "Check examples a*b vs b*a; look for counterexamples."
 
128
  @tool
129
  def data_extractor(source: str, target: str) -> str:
130
  """
131
+ Extracts specific data elements from a source string based on a target keyword.
132
 
133
  Args:
134
+ source (str): The text to extract data from.
135
+ target (str): The keyword or category of data to extract (e.g., 'botanical vegetables').
136
 
137
  Returns:
138
+ str: Extracted information or a message if nothing is found.
139
  """
140
  if "botanical" in target.lower() and "vegetable" in source:
141
  items = [i.strip() for i in source.split(",")]
 
143
  return ", ".join(true_veg) or "No true vegetables found."
144
  return f"Extract {target} from source..."
145
 
146
+
147
  # --- Agent Setup ---
148
  class GAIAAgent:
149
  def __init__(self):