Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,15 +8,32 @@ 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 |
-
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +72,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
ddg_tool_instance = DuckDuckGoSearchTool()
|
| 12 |
+
|
| 13 |
@tool
|
| 14 |
+
def web_search(query: str, max_results: int = 5) -> str:
|
| 15 |
+
"""
|
| 16 |
+
Search the web for up-to-date information using DuckDuckGo.
|
| 17 |
+
|
| 18 |
Args:
|
| 19 |
+
query: The search query (e.g. "Elon Musk current net worth")
|
| 20 |
+
max_results: Maximum number of results to return
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
A string containing the top search results or a message if no results found.
|
| 24 |
"""
|
| 25 |
+
try:
|
| 26 |
+
results = ddg_tool_instance.run(query)
|
| 27 |
+
if not results:
|
| 28 |
+
return "No results found! Try a less restrictive/shorter query."
|
| 29 |
+
|
| 30 |
+
# Если пришёл список, берём только топ N результатов
|
| 31 |
+
top_results = results[:max_results] if isinstance(results, list) else [results]
|
| 32 |
+
|
| 33 |
+
# Собираем в строку
|
| 34 |
+
return "\n".join(top_results)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error during web search: {str(e)}"
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 72 |
|
| 73 |
agent = CodeAgent(
|
| 74 |
model=model,
|
| 75 |
+
tools=[final_answer, get_current_time_in_timezone, web_search], ## add your tools here (don't remove final answer)
|
| 76 |
max_steps=6,
|
| 77 |
verbosity_level=1,
|
| 78 |
grammar=None,
|