Spaces:
Runtime error
Runtime error
fix
Browse files
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 |
-
|
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
|
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 |
-
|
74 |
|
75 |
Args:
|
76 |
-
query (str): The search
|
77 |
|
78 |
Returns:
|
79 |
-
str: A summary
|
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 |
-
|
98 |
|
99 |
Args:
|
100 |
-
text (str): The input
|
101 |
-
operation (str): The operation to perform. Options
|
102 |
|
103 |
Returns:
|
104 |
-
str: The result of the text
|
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 |
-
|
118 |
|
119 |
Args:
|
120 |
-
problem (str): A math question or
|
121 |
|
122 |
Returns:
|
123 |
-
str: An explanation or analysis
|
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 |
-
|
134 |
|
135 |
Args:
|
136 |
-
source (str): The
|
137 |
-
target (str): The
|
138 |
|
139 |
Returns:
|
140 |
-
str:
|
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):
|