Spaces:
Sleeping
Sleeping
added new tool for quick search web.
Browse files
app.py
CHANGED
|
@@ -8,15 +8,34 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
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 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +74,7 @@ with open("prompts.yaml", 'r') as 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,
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
|
| 12 |
+
|
| 13 |
@tool
|
| 14 |
+
def quick_search_tool(content:str,int: max_results= 5)-> str: #it's import to specify the return type
|
| 15 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 16 |
+
"""A tool that search web for glance over given topic.
|
| 17 |
Args:
|
| 18 |
+
content: The text that searched in web. (string)
|
| 19 |
+
max_results: The number of result .Maximum results count =5 (integer)
|
| 20 |
"""
|
| 21 |
+
try:
|
| 22 |
+
search_tool = DuckDuckGoSearchTool()
|
| 23 |
+
results = search_tool.run(content, max_results)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
summary = f"topics about |{result}| : \n"
|
| 27 |
+
for i, result in enumerate(results[:max_results],1):
|
| 28 |
+
summary+= f"{i} : {results['title'] {results['snippets']} \n "
|
| 29 |
+
return summary.split()
|
| 30 |
+
|
| 31 |
+
except Exception as e
|
| 32 |
+
|
| 33 |
+
return f"Error when searching : {e}"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 74 |
|
| 75 |
agent = CodeAgent(
|
| 76 |
model=model,
|
| 77 |
+
tools=[final_answer,quick_search_tool], ## add your tools here (don't remove final answer)
|
| 78 |
max_steps=6,
|
| 79 |
verbosity_level=1,
|
| 80 |
grammar=None,
|