Added tools
#235
by
Nishanth88
- opened
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -9,14 +9,18 @@ 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 |
-
arg2: the second argument
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -40,22 +44,21 @@ final_answer = FinalAnswerTool()
|
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
42 |
model = HfApiModel(
|
43 |
-
max_tokens=2096,
|
44 |
-
temperature=0.5,
|
45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
46 |
-
custom_role_conversions=None,
|
47 |
)
|
48 |
|
49 |
-
|
50 |
# Import tool from Hub
|
51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
52 |
|
53 |
with open("prompts.yaml", 'r') as stream:
|
54 |
prompt_templates = yaml.safe_load(stream)
|
55 |
-
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ##
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
@@ -65,5 +68,4 @@ agent = CodeAgent(
|
|
65 |
prompt_templates=prompt_templates
|
66 |
)
|
67 |
|
68 |
-
|
69 |
GradioUI(agent).launch()
|
|
|
1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def duckduckgo_search(query: str) -> str:
|
13 |
+
"""A tool that performs a DuckDuckGo search and returns the top search result.
|
|
|
14 |
Args:
|
15 |
+
query: A search query string.
|
|
|
16 |
"""
|
17 |
+
response = requests.get(f"https://api.duckduckgo.com/?q={query}&format=json")
|
18 |
+
data = response.json()
|
19 |
+
if "AbstractText" in data and data["AbstractText"]:
|
20 |
+
return data["AbstractText"]
|
21 |
+
elif "RelatedTopics" in data and data["RelatedTopics"]:
|
22 |
+
return data["RelatedTopics"][0].get("Text", "No relevant results found.")
|
23 |
+
return "No relevant search results found."
|
24 |
|
25 |
@tool
|
26 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
44 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
45 |
|
46 |
model = HfApiModel(
|
47 |
+
max_tokens=2096,
|
48 |
+
temperature=0.5,
|
49 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
50 |
+
custom_role_conversions=None,
|
51 |
)
|
52 |
|
|
|
53 |
# Import tool from Hub
|
54 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
55 |
|
56 |
with open("prompts.yaml", 'r') as stream:
|
57 |
prompt_templates = yaml.safe_load(stream)
|
58 |
+
|
59 |
agent = CodeAgent(
|
60 |
model=model,
|
61 |
+
tools=[final_answer, duckduckgo_search, get_current_time_in_timezone, image_generation_tool], ## Added all tools
|
62 |
max_steps=6,
|
63 |
verbosity_level=1,
|
64 |
grammar=None,
|
|
|
68 |
prompt_templates=prompt_templates
|
69 |
)
|
70 |
|
|
|
71 |
GradioUI(agent).launch()
|