Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,15 @@ from duckduckgo_search import DDGS
|
|
| 11 |
# --- Tools ---
|
| 12 |
@tool
|
| 13 |
def web_search(query: str) -> str:
|
| 14 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
with DDGS() as ddgs:
|
| 17 |
results = ddgs.text(query, max_results=3)
|
|
@@ -20,18 +28,27 @@ def web_search(query: str) -> str:
|
|
| 20 |
for r in results
|
| 21 |
) if results else "No results found."
|
| 22 |
except Exception as e:
|
| 23 |
-
return f"Search error: {e}"
|
|
|
|
| 24 |
|
| 25 |
@tool
|
| 26 |
def calculate(expression: str) -> str:
|
| 27 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
try:
|
| 29 |
safe_dict = {k: v for k, v in math.__dict__.items() if not k.startswith("__")}
|
| 30 |
safe_dict.update({'abs': abs, 'round': round})
|
| 31 |
result = eval(expression, {"__builtins__": None}, safe_dict)
|
| 32 |
return str(result)
|
| 33 |
except Exception as e:
|
| 34 |
-
return f"Calculation error: {e}"
|
| 35 |
|
| 36 |
# --- Agent ---
|
| 37 |
class GAIAAgent:
|
|
|
|
| 11 |
# --- Tools ---
|
| 12 |
@tool
|
| 13 |
def web_search(query: str) -> str:
|
| 14 |
+
"""
|
| 15 |
+
Perform a web search using DuckDuckGo.
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
query (str): The search query string.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
str: A formatted string with search results.
|
| 22 |
+
"""
|
| 23 |
try:
|
| 24 |
with DDGS() as ddgs:
|
| 25 |
results = ddgs.text(query, max_results=3)
|
|
|
|
| 28 |
for r in results
|
| 29 |
) if results else "No results found."
|
| 30 |
except Exception as e:
|
| 31 |
+
return f"Search error: {str(e)}"
|
| 32 |
+
|
| 33 |
|
| 34 |
@tool
|
| 35 |
def calculate(expression: str) -> str:
|
| 36 |
+
"""
|
| 37 |
+
Evaluate a mathematical expression safely.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
expression (str): The math expression to evaluate.
|
| 41 |
+
|
| 42 |
+
Returns:
|
| 43 |
+
str: The result as a string, or an error message.
|
| 44 |
+
"""
|
| 45 |
try:
|
| 46 |
safe_dict = {k: v for k, v in math.__dict__.items() if not k.startswith("__")}
|
| 47 |
safe_dict.update({'abs': abs, 'round': round})
|
| 48 |
result = eval(expression, {"__builtins__": None}, safe_dict)
|
| 49 |
return str(result)
|
| 50 |
except Exception as e:
|
| 51 |
+
return f"Calculation error: {str(e)}"
|
| 52 |
|
| 53 |
# --- Agent ---
|
| 54 |
class GAIAAgent:
|