Spaces:
Runtime error
Runtime error
Deploy GAIA agent
Browse files
app.py
CHANGED
@@ -22,24 +22,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
22 |
|
23 |
# --- Enhanced Tools for GAIA ---
|
24 |
|
|
|
25 |
from duckduckgo_search import DDGS
|
26 |
|
|
|
27 |
def web_search_tool(query: str) -> str:
|
28 |
"""
|
29 |
-
|
30 |
|
31 |
Args:
|
32 |
-
query (str):
|
33 |
|
34 |
Returns:
|
35 |
-
str:
|
36 |
"""
|
37 |
try:
|
38 |
with DDGS() as ddgs:
|
39 |
-
results = ddgs.text(query, max_results=
|
40 |
output = []
|
41 |
-
for
|
42 |
-
output.append(f"Title: {
|
43 |
return "\n\n".join(output)
|
44 |
except Exception as e:
|
45 |
return f"Web search failed: {str(e)}"
|
|
|
22 |
|
23 |
# --- Enhanced Tools for GAIA ---
|
24 |
|
25 |
+
from smolagents import tool
|
26 |
from duckduckgo_search import DDGS
|
27 |
|
28 |
+
@tool
|
29 |
def web_search_tool(query: str) -> str:
|
30 |
"""
|
31 |
+
Perform a web search using DuckDuckGo and return top results.
|
32 |
|
33 |
Args:
|
34 |
+
query (str): Search query.
|
35 |
|
36 |
Returns:
|
37 |
+
str: Formatted search result string.
|
38 |
"""
|
39 |
try:
|
40 |
with DDGS() as ddgs:
|
41 |
+
results = ddgs.text(query, max_results=3)
|
42 |
output = []
|
43 |
+
for r in results:
|
44 |
+
output.append(f"Title: {r['title']}\nURL: {r['href']}\nSnippet: {r['body']}")
|
45 |
return "\n\n".join(output)
|
46 |
except Exception as e:
|
47 |
return f"Web search failed: {str(e)}"
|