Spaces:
Sleeping
Sleeping
added search tool
Browse files
app.py
CHANGED
|
@@ -7,16 +7,19 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a
|
| 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,7 +40,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 +55,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,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# Below is an example of a search tool
|
| 11 |
@tool
|
| 12 |
+
def search_internet(query: str) -> str: #it's import to specify the return type
|
| 13 |
+
"""A tool that searches the internet for information using DuckDuckGo.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
query: The search query.
|
|
|
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
search_tool = DuckDuckGoSearchTool()
|
| 19 |
+
results = search_tool.run(query)
|
| 20 |
+
return f"Search results for '{query}':\n{results}"
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"Error during internet search for '{query}': {str(e)}"
|
| 23 |
|
| 24 |
@tool
|
| 25 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 40 |
final_answer = FinalAnswerTool()
|
| 41 |
|
| 42 |
# 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:
|
| 43 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 44 |
|
| 45 |
model = HfApiModel(
|
| 46 |
max_tokens=2096,
|
|
|
|
| 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, search_internet, get_current_time_in_timezone, image_generation_tool], ## add your tools here (don't remove final answer)
|
| 62 |
max_steps=6,
|
| 63 |
verbosity_level=1,
|
| 64 |
grammar=None,
|