added duckduckgo search tool
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ 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 +18,35 @@ 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.
|
@@ -56,7 +85,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
56 |
|
57 |
agent = CodeAgent(
|
58 |
model=model,
|
59 |
-
tools=[get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
|
60 |
max_steps=6,
|
61 |
verbosity_level=1,
|
62 |
grammar=None,
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from duckduckgo_search import DDGS
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
18 |
"""
|
19 |
return "What magic will you build ?"
|
20 |
|
21 |
+
@tool
|
22 |
+
def ddg_tool(query:str, area:str, max_results:int=5)-> list: # it's important to specify the return type
|
23 |
+
# Keep this format for the tool description / args description but feel free to modify the tool
|
24 |
+
"""A tool that searches for restaraunts in a particular location using DuckDuckGo search.
|
25 |
+
Args:
|
26 |
+
query: The type of restaraunt cuisine or keyword (e.g. "italian").
|
27 |
+
area: The city and state in which the restaraunts are located (e.g. "San Diego, CA").
|
28 |
+
max_results: Number of results to return. Maximum number is 5.
|
29 |
+
Returns: List of dictionaries with Restaurant Name, city, and URL.
|
30 |
+
"""
|
31 |
+
# Instantiate the tool
|
32 |
+
ddg_tool = DDGS()
|
33 |
+
|
34 |
+
# Modify query to include city for better results
|
35 |
+
full_query = f"{query} restaurant in {area}"
|
36 |
+
|
37 |
+
# Fetch results
|
38 |
+
search_results = DDGS().text(full_query, max_results=max_results)
|
39 |
+
|
40 |
+
results = []
|
41 |
+
for result in search_results:
|
42 |
+
results.append({
|
43 |
+
"title": result.get("title", "No Title"),
|
44 |
+
"url": result.get("href", "No URL"),
|
45 |
+
"snippet": result.get("body", "No Description")
|
46 |
+
})
|
47 |
+
|
48 |
+
return results
|
49 |
+
|
50 |
@tool
|
51 |
def get_current_time_in_timezone(timezone: str) -> str:
|
52 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
85 |
|
86 |
agent = CodeAgent(
|
87 |
model=model,
|
88 |
+
tools=[ddg_tool,get_current_time_in_timezone,final_answer], ## add your tools here (don't remove final answer)
|
89 |
max_steps=6,
|
90 |
verbosity_level=1,
|
91 |
grammar=None,
|