Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,15 +8,38 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
# Edit: now updated to conduct a web search
|
| 12 |
+
|
| 13 |
@tool
|
| 14 |
+
def make_web_search(query: str) -> str:
|
| 15 |
+
"""A tool that conducts a web search using DuckDuckGo
|
|
|
|
| 16 |
Args:
|
| 17 |
+
query: A string representing a valid query for a web search.
|
| 18 |
+
Returns:
|
| 19 |
+
A string containing the search results or an error message.
|
| 20 |
"""
|
| 21 |
+
try:
|
| 22 |
+
# Initialize the DuckDuckGo search tool
|
| 23 |
+
search_tool = DuckDuckGoSearchTool()
|
| 24 |
+
|
| 25 |
+
# Perform the search
|
| 26 |
+
results = search_tool.run(query)
|
| 27 |
+
|
| 28 |
+
# Format the results
|
| 29 |
+
if not results:
|
| 30 |
+
return "No results found for your query."
|
| 31 |
+
|
| 32 |
+
formatted_results = []
|
| 33 |
+
for i, result in enumerate(results[:3], 1): # Show top 3 results
|
| 34 |
+
formatted_results.append(
|
| 35 |
+
f"{i}. {result.get('title', 'No title')}\n"
|
| 36 |
+
f" URL: {result.get('link', 'No URL')}\n"
|
| 37 |
+
f" Description: {result.get('body', 'No description')}\n"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
return f"Web search results for '{query}':\n" + "\n".join(formatted_results)
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error performing web search: {str(e)}"
|
| 43 |
|
| 44 |
@tool
|
| 45 |
def get_current_time_in_timezone(timezone: str) -> str:
|