Update app.py
Browse filesCorrecting again search_web tool
app.py
CHANGED
|
@@ -14,8 +14,22 @@ def search_web(query:str)-> str: #it's import to specify the return type
|
|
| 14 |
Args:
|
| 15 |
query: the query to search the web
|
| 16 |
"""
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
@tool
|
|
|
|
| 14 |
Args:
|
| 15 |
query: the query to search the web
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
web_search_tool = DuckDuckGoSearchTool(max_results=5, rate_limit=2.0)
|
| 19 |
+
results = web_search_tool(query)
|
| 20 |
+
|
| 21 |
+
if not results:
|
| 22 |
+
return "No results found."
|
| 23 |
+
|
| 24 |
+
# Format results into readable text
|
| 25 |
+
formatted = "\n".join(
|
| 26 |
+
[f"{i+1}. {r.get('title', 'No title')} - {r.get('link', 'No link')}\n{r.get('snippet', '')}"
|
| 27 |
+
for i, r in enumerate(results)]
|
| 28 |
+
)
|
| 29 |
+
return formatted
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error during web search: {str(e)}"
|
| 33 |
|
| 34 |
|
| 35 |
@tool
|