Spaces:
Sleeping
Sleeping
ekhatskevich
commited on
Commit
·
f944cf1
1
Parent(s):
ae7a494
add search tool
Browse files
app.py
CHANGED
@@ -1,22 +1,24 @@
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
3 |
-
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
|
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:
|
@@ -37,13 +39,13 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
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',# it is possible that this model may be overloaded
|
46 |
-
custom_role_conversions=None,
|
47 |
)
|
48 |
|
49 |
|
@@ -52,10 +54,10 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
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], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
import datetime
|
|
|
3 |
import pytz
|
4 |
import yaml
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
|
7 |
from Gradio_UI import GradioUI
|
8 |
|
9 |
+
|
10 |
@tool
|
11 |
+
def search(query: str)-> str:
|
12 |
+
"""A tool that searches the Internet for the best answer for a request.
|
|
|
13 |
Args:
|
14 |
+
query: A string with search request
|
|
|
15 |
"""
|
16 |
+
try:
|
17 |
+
search_tool = DuckDuckGoSearchTool()
|
18 |
+
response = search_tool.forward(query)
|
19 |
+
return response
|
20 |
+
except Exception as e:
|
21 |
+
return f"Error fetching the response for query '{query}': {str(e)}"
|
22 |
|
23 |
@tool
|
24 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
39 |
final_answer = FinalAnswerTool()
|
40 |
|
41 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
42 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
43 |
|
44 |
model = HfApiModel(
|
45 |
+
max_tokens=2096,
|
46 |
+
temperature=0.5,
|
47 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
48 |
+
custom_role_conversions=None,
|
49 |
)
|
50 |
|
51 |
|
|
|
54 |
|
55 |
with open("prompts.yaml", 'r') as stream:
|
56 |
prompt_templates = yaml.safe_load(stream)
|
57 |
+
|
58 |
agent = CodeAgent(
|
59 |
model=model,
|
60 |
+
tools=[final_answer,search], ## add your tools here (don't remove final answer)
|
61 |
max_steps=6,
|
62 |
verbosity_level=1,
|
63 |
grammar=None,
|