Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -41,7 +42,29 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 41 |
except Exception as e:
|
| 42 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
|
|
|
| 45 |
final_answer = FinalAnswerTool()
|
| 46 |
|
| 47 |
# 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:
|
|
@@ -67,10 +90,10 @@ agent = CodeAgent(
|
|
| 67 |
tools=[
|
| 68 |
final_answer,
|
| 69 |
get_current_time_in_timezone,
|
| 70 |
-
|
| 71 |
image_generation_tool,
|
| 72 |
rickroll
|
| 73 |
-
],
|
| 74 |
max_steps=6,
|
| 75 |
verbosity_level=1,
|
| 76 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
+
from ddgs import DDGS
|
| 3 |
import datetime
|
| 4 |
import requests
|
| 5 |
import pytz
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 44 |
|
| 45 |
+
@tool
|
| 46 |
+
def web_search(query: str) -> str:
|
| 47 |
+
"""Searches the internet for information.
|
| 48 |
+
If the search fails, do not repeatedly retry it.
|
| 49 |
+
Args:
|
| 50 |
+
query: The search terms to look up.
|
| 51 |
+
"""
|
| 52 |
+
try:
|
| 53 |
+
results = DDGS().text(query, max_results=5)
|
| 54 |
+
|
| 55 |
+
print("SEARCH QUERY:", query)
|
| 56 |
+
print("SEARCH RESULTS:", results)
|
| 57 |
+
|
| 58 |
+
if not results:
|
| 59 |
+
return "No results found. Do not retry."
|
| 60 |
+
|
| 61 |
+
return str(results)
|
| 62 |
+
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print("SEARCH ERROR:", repr(e))
|
| 65 |
+
return f"Search failed: {e}. Do not retry."
|
| 66 |
|
| 67 |
+
|
| 68 |
final_answer = FinalAnswerTool()
|
| 69 |
|
| 70 |
# 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:
|
|
|
|
| 90 |
tools=[
|
| 91 |
final_answer,
|
| 92 |
get_current_time_in_timezone,
|
| 93 |
+
web_search,
|
| 94 |
image_generation_tool,
|
| 95 |
rickroll
|
| 96 |
+
],
|
| 97 |
max_steps=6,
|
| 98 |
verbosity_level=1,
|
| 99 |
grammar=None,
|