Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,42 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 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 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +81,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,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
|
| 11 |
+
class CustomDuckDuckGoSearchTool(DuckDuckGoSearchTool):
|
| 12 |
+
name = "web_search"
|
| 13 |
+
description = "Performs a web search for a query and returns a list of the top search results formatted as markdown with page titles and urls."
|
| 14 |
+
inputs = {"query": {"type": "string", "description": "The search query to perform."}}
|
| 15 |
+
output_type = "string"
|
| 16 |
+
|
| 17 |
+
def __init__(self, max_results: int = 10, rate_limit: float | None = 1.0, backend: str = "auto", **kwargs):
|
| 18 |
+
super().__init__(max_results=max_results, rate_limit=rate_limit, **kwargs)
|
| 19 |
+
self.backend = backend # Add "backend" as new parameter
|
| 20 |
+
|
| 21 |
+
def forward(self, query: str) -> str:
|
| 22 |
+
self._enforce_rate_limit()
|
| 23 |
+
results = self.ddgs.text(
|
| 24 |
+
query=query,
|
| 25 |
+
max_results=self.max_results,
|
| 26 |
+
backend=self.backend) # there you go
|
| 27 |
+
if len(results) == 0:
|
| 28 |
+
raise Exception("No results found! Try a less restrictive/shorter query.")
|
| 29 |
+
postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
|
| 30 |
+
return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
|
| 31 |
+
|
| 32 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 33 |
@tool
|
| 34 |
+
def capital_of_country(country:str)-> str: #it's import to specify the return type
|
| 35 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 36 |
+
"""A tool that get the capital of country passd by the user
|
| 37 |
Args:
|
| 38 |
+
country: country name
|
|
|
|
| 39 |
"""
|
| 40 |
+
tool = CustomDuckDuckGoSearchTool(
|
| 41 |
+
max_results=3,
|
| 42 |
+
rate_limit=1.0,
|
| 43 |
+
backend="google")
|
| 44 |
+
result = tool(query=country)
|
| 45 |
+
return result
|
| 46 |
|
| 47 |
@tool
|
| 48 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 81 |
|
| 82 |
agent = CodeAgent(
|
| 83 |
model=model,
|
| 84 |
+
tools=[final_answer],[capital_of_country],[get_current_time_in_timezone] ## add your tools here (don't remove final answer)
|
| 85 |
max_steps=6,
|
| 86 |
verbosity_level=1,
|
| 87 |
grammar=None,
|