Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -55,7 +73,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,
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
| 37 |
+
# Web Search Tool (DuckDuckGo)
|
| 38 |
+
@tool
|
| 39 |
+
def web_search(query: str) -> str:
|
| 40 |
+
"""Performs a web search using DuckDuckGo and returns relevant results.
|
| 41 |
+
Args:
|
| 42 |
+
query: The search query string
|
| 43 |
+
Returns:
|
| 44 |
+
str: Formatted search results
|
| 45 |
+
"""
|
| 46 |
+
try:
|
| 47 |
+
search_results = DuckDuckGoSearchTool()(query=query)
|
| 48 |
+
# Format results for better readability
|
| 49 |
+
formatted_results = "\n".join([f"{i+1}. {result['title']}\n {result['link']}\n {result['snippet']}" for i, result in enumerate(search_results[:3]) # Show top 3 results
|
| 50 |
+
return f"Web search results for '{query}':\n{formatted_results}"
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return f"Search error: {str(e)}"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
final_answer = FinalAnswerTool()
|
| 56 |
|
| 57 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[final_answer, web_search], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|