Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,15 +13,17 @@ def my_custom_tool(query:str)-> str: #it's import to specify the return type
|
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""Searches the web via DuckDuckGo to retrieve the top 3 most relevant results. Use this tool whenever you need up-to-date information, news, or facts that are not in your training data.
|
| 15 |
Args:
|
| 16 |
-
query:
|
| 17 |
"""
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
@tool
|
| 27 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""Searches the web via DuckDuckGo to retrieve the top 3 most relevant results. Use this tool whenever you need up-to-date information, news, or facts that are not in your training data.
|
| 15 |
Args:
|
| 16 |
+
query: The search query. Keep it simple and keyword-based.
|
| 17 |
"""
|
| 18 |
|
| 19 |
+
try:
|
| 20 |
+
search_engine = DuckDuckGoSearchTool(max_results=3)
|
| 21 |
+
# Execute the search
|
| 22 |
+
results = search_engine(query)
|
| 23 |
+
return results
|
| 24 |
+
except Exception as e:
|
| 25 |
+
# If DDG fails, we return a message to the agent instead of crashing
|
| 26 |
+
return f"Error: {str(e)}. Advice: Try a broader or shorter search query (e.g., instead of 'price of bitcoin on March 31 2026', just try 'bitcoin price')."
|
| 27 |
|
| 28 |
@tool
|
| 29 |
def get_current_time_in_timezone(timezone: str) -> str:
|