Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,28 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
| 24 |
Args:
|
|
@@ -55,7 +77,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
+
def get_search(query: str, num_results: int = 5) -> str:
|
| 23 |
+
"""A tool that searches the web using DuckDuckGo.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
query: The search query string
|
| 27 |
+
num_results: The number of search results to return (default: 5)
|
| 28 |
+
"""
|
| 29 |
+
try:
|
| 30 |
+
search_tool = DuckDuckGoSearchTool()
|
| 31 |
+
results = search_tool(query, num_results)
|
| 32 |
+
|
| 33 |
+
# Format the results in a readable way
|
| 34 |
+
formatted_results = "Search Results:\n\n"
|
| 35 |
+
for i, result in enumerate(results, 1):
|
| 36 |
+
formatted_results += f"{i}. {result['title']}\n"
|
| 37 |
+
formatted_results += f" URL: {result['link']}\n"
|
| 38 |
+
formatted_results += f" Snippet: {result['snippet']}\n\n"
|
| 39 |
+
|
| 40 |
+
return formatted_results
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error performing search for '{query}': {str(e)}"
|
| 43 |
+
@tool
|
| 44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 45 |
"""A tool that fetches the current local time in a specified timezone.
|
| 46 |
Args:
|
|
|
|
| 77 |
|
| 78 |
agent = CodeAgent(
|
| 79 |
model=model,
|
| 80 |
+
tools=[get_search, get_current_time_in_timezone, my_custom_tool, image_generation_tool, final_answer], ## add your tools here (don't remove final answer)
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|
| 83 |
grammar=None,
|