Spaces:
Runtime error
Runtime error
Duygu Jones
commited on
Update app.py
Browse filesThe Tavily web search tool has been added.
And the necessary libraries are imported.
app.py
CHANGED
|
@@ -4,7 +4,8 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
@@ -18,6 +19,19 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 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.
|
|
@@ -55,7 +69,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import os
|
| 8 |
+
from tavily import TavilyClient
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
@tool
|
| 23 |
+
def tavily_search(query: str) -> str:
|
| 24 |
+
"""A tool that performs web search using Tavily API
|
| 25 |
+
Args:
|
| 26 |
+
query: The search query to look up
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
|
| 30 |
+
search_result = client.search(query=query)
|
| 31 |
+
return str(search_result)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Error performing search: {str(e)}"
|
| 34 |
+
|
| 35 |
@tool
|
| 36 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 37 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 69 |
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[final_answer, tavily_search, get_current_time_in_timezone, image_generation_tool], # Added tavily_search
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|