Spaces:
Runtime error
Runtime error
Deploy GAIA agent
Browse files
app.py
CHANGED
@@ -32,20 +32,56 @@ def web_search_tool(query: str) -> str:
|
|
32 |
String containing search results
|
33 |
"""
|
34 |
try:
|
35 |
-
#
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
results = []
|
40 |
for r in search_results:
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
if
|
44 |
-
return "No search results found."
|
45 |
|
46 |
-
return "\n\n".join(results)
|
47 |
except Exception as e:
|
48 |
-
return f"Search
|
49 |
|
50 |
@tool
|
51 |
def calculator_tool(expression: str) -> str:
|
|
|
32 |
String containing search results
|
33 |
"""
|
34 |
try:
|
35 |
+
# Try multiple approaches for DDGS
|
36 |
+
search_results = []
|
37 |
+
|
38 |
+
# Approach 1: Basic DDGS
|
39 |
+
try:
|
40 |
+
ddgs = DDGS()
|
41 |
+
search_results = list(ddgs.text(query, max_results=5))
|
42 |
+
except Exception as e1:
|
43 |
+
print(f"DDGS Approach 1 failed: {e1}")
|
44 |
+
|
45 |
+
# Approach 2: Try with timeout parameter only
|
46 |
+
try:
|
47 |
+
ddgs = DDGS(timeout=10)
|
48 |
+
search_results = list(ddgs.text(query, max_results=5))
|
49 |
+
except Exception as e2:
|
50 |
+
print(f"DDGS Approach 2 failed: {e2}")
|
51 |
+
|
52 |
+
# Approach 3: Minimal call without max_results
|
53 |
+
try:
|
54 |
+
ddgs = DDGS()
|
55 |
+
search_results = list(ddgs.text(query))[:5] # Limit results manually
|
56 |
+
except Exception as e3:
|
57 |
+
print(f"DDGS Approach 3 failed: {e3}")
|
58 |
+
|
59 |
+
# Approach 4: Try older style initialization
|
60 |
+
try:
|
61 |
+
from duckduckgo_search import ddg
|
62 |
+
search_results = ddg(query, max_results=5)
|
63 |
+
except Exception as e4:
|
64 |
+
print(f"DDGS Approach 4 failed: {e4}")
|
65 |
+
return f"All DDGS approaches failed. Last error: {e4}"
|
66 |
+
|
67 |
+
if not search_results:
|
68 |
+
return "No search results found."
|
69 |
|
70 |
results = []
|
71 |
for r in search_results:
|
72 |
+
try:
|
73 |
+
title = r.get('title', 'No title')
|
74 |
+
url = r.get('href', 'No URL')
|
75 |
+
snippet = r.get('body', 'No snippet')
|
76 |
+
results.append(f"Title: {title}\nURL: {url}\nSnippet: {snippet}")
|
77 |
+
except Exception as parse_error:
|
78 |
+
print(f"Error parsing result: {parse_error}")
|
79 |
+
continue
|
80 |
|
81 |
+
return "\n\n".join(results) if results else "No valid results could be parsed."
|
|
|
82 |
|
|
|
83 |
except Exception as e:
|
84 |
+
return f"Search tool error: {str(e)}"
|
85 |
|
86 |
@tool
|
87 |
def calculator_tool(expression: str) -> str:
|