Spaces:
Sleeping
Sleeping
shaolang
commited on
Commit
·
442ae8b
1
Parent(s):
71b5107
Customize tool to search the internet using DuckDuckGo
Browse files
app.py
CHANGED
@@ -9,14 +9,14 @@ 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 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
"""A tool that
|
15 |
Args:
|
16 |
-
|
17 |
-
arg2: the second argument
|
18 |
"""
|
19 |
-
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -37,7 +37,7 @@ 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,
|
@@ -52,10 +52,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,
|
@@ -66,4 +66,4 @@ agent = CodeAgent(
|
|
66 |
)
|
67 |
|
68 |
|
69 |
-
GradioUI(agent).launch()
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def search_internet(query: str)-> str: #it's import to specify the return type
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
+
"""A tool that sends a query to a search engine and returns the seach results
|
15 |
Args:
|
16 |
+
query: A string representing the search query
|
|
|
17 |
"""
|
18 |
+
ddg = DuckDuckGoSearchTool()
|
19 |
+
return ddg.forward(query)
|
20 |
|
21 |
@tool
|
22 |
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,
|
|
|
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, search_internet], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
66 |
)
|
67 |
|
68 |
|
69 |
+
GradioUI(agent).launch()
|