Spaces:
Runtime error
Runtime error
Update app.py
Browse filesfeat: adds web search
app.py
CHANGED
|
@@ -33,6 +33,19 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +68,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def web_search(query: str) -> str:
|
| 38 |
+
"""Performs a web search using DuckDuckGo and return the first result
|
| 39 |
+
Args:
|
| 40 |
+
query: The search query string
|
| 41 |
+
"""
|
| 42 |
+
search_tool = DuckDuckGoSearchTool()
|
| 43 |
+
results = search_tool(query)
|
| 44 |
+
|
| 45 |
+
if isinstance(results, list) and len(results) > 0:
|
| 46 |
+
return f"Top result for '{query}': {results[0]['body']} (link: {results[0]['href']})"
|
| 47 |
+
else:
|
| 48 |
+
return f"No results found for query: {query}"
|
| 49 |
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
|
|
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
+
tools=[final_answer, web_search], ## add your tools here (don't remove final answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|