MarcoM003 commited on
Commit
ed99bcb
·
verified ·
1 Parent(s): c3e0b0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -31
app.py CHANGED
@@ -8,28 +8,19 @@ 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 search_ddgs(query:str, max_results:int=5)-> list: #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 searches the internet to answer user's question and returns top research results.
15
-
16
- # Args:
17
- # query: The search query
18
- # max_results: Number of results to return. Maximum number is 5.
19
-
20
- # Returns:
21
- # List of dictionaries with title, URL, and description.
22
- # """
23
- # results = []
24
- # with DuckDuckGoSearchTool as ddgs:
25
- # for result in ddgs.text(query, max_results = max_results):
26
- # results.append({
27
- # "title": result["title"],
28
- # "url": result["href"],
29
- # "snippet":result["body"]
30
- # })
31
-
32
- # return results
33
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -49,13 +40,6 @@ def get_current_time_in_timezone(timezone: str) -> str:
49
 
50
  final_answer = FinalAnswerTool()
51
 
52
- # Import tool from Hub
53
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
54
-
55
- # Search tool
56
- search_tool = DuckDuckGoSearchTool()
57
- # search_tool = DuckDuckGoSearchTool(max_results=3, output_format="json")
58
-
59
  # 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:
60
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
61
 
@@ -67,14 +51,15 @@ custom_role_conversions=None,
67
  )
68
 
69
 
70
-
 
71
 
72
  with open("prompts.yaml", 'r') as stream:
73
  prompt_templates = yaml.safe_load(stream)
74
 
75
  agent = CodeAgent(
76
  model=model,
77
- tools=[final_answer, get_current_time_in_timezone, search_tool, image_generation_tool], ## add your tools here (don't remove final answer)
78
  max_steps=6,
79
  verbosity_level=1,
80
  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
+ @tool
12
+ def my_search_tool(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 searches DuckDuckGo for a given query.
15
+ Args:
16
+ query: The search query.
17
+ Returns:
18
+ response: The response with the search results.
19
+ """
20
+ search_tool = DuckDuckGoSearchTool()
21
+ search_results = search_tool(query)
22
+ response = f"Here's what i've found about {query}: {search_results}"
23
+ return response
 
 
 
 
 
 
 
 
 
24
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
 
40
 
41
  final_answer = FinalAnswerTool()
42
 
 
 
 
 
 
 
 
43
  # 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:
44
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
45
 
 
51
  )
52
 
53
 
54
+ # Import tool from Hub
55
+ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
56
 
57
  with open("prompts.yaml", 'r') as stream:
58
  prompt_templates = yaml.safe_load(stream)
59
 
60
  agent = CodeAgent(
61
  model=model,
62
+ tools=[my_search_tool, final_answer], ## add your tools here (don't remove final answer)
63
  max_steps=6,
64
  verbosity_level=1,
65
  grammar=None,