Aramide commited on
Commit
dbb91ca
·
verified ·
1 Parent(s): 7e54aab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -1,4 +1,3 @@
1
- !pip install duckduckgo_search
2
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
3
  import datetime
4
  import requests
@@ -11,35 +10,35 @@ from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
 
14
- @tool
15
- def web_search_tool(query: str, num_results: int = 3) -> str:
16
- """A tool that performs a web search and fetches up-to-date information using DuckDuckGo.
17
 
18
- Args:
19
- query: The search query or topic to look up on the web.
20
- num_results: The number of top search results to return (default is 3).
21
 
22
- Returns:
23
- A string containing summarized up-to-date information from the web.
24
- """
25
- try:
26
- ddg = DuckDuckGoSearchTool()
27
- results = ddg.text(query, max_results=num_results)
28
 
29
- if not results:
30
- return f"No results found for '{query}'."
31
 
32
- info_list = []
33
- for i, r in enumerate(results):
34
- title = r.get("title", "No title")
35
- body = r.get("body", "No summary available.")
36
- link = r.get("href", "")
37
- info_list.append(f"{i+1}. {title}\n{body}\n({link})")
38
 
39
- return f"Here are the top {num_results} results for '{query}':\n\n" + "\n\n".join(info_list)
40
 
41
- except Exception as e:
42
- return f"Error performing web search for '{query}': {str(e)}"
43
 
44
 
45
 
@@ -75,12 +74,14 @@ custom_role_conversions=None,
75
  # Import tool from Hub
76
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
77
 
 
 
78
  with open("prompts.yaml", 'r') as stream:
79
  prompt_templates = yaml.safe_load(stream)
80
 
81
  agent = CodeAgent(
82
  model=model,
83
- tools=[final_answer, get_current_time_in_timezone, web_search_tool], ## add your tools here (don't remove final answer)
84
  max_steps=6,
85
  verbosity_level=1,
86
  grammar=None,
 
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
 
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
 
13
+ # @tool
14
+ # def web_search_tool(query: str, num_results: int = 3) -> str:
15
+ # """A tool that performs a web search and fetches up-to-date information using DuckDuckGo.
16
 
17
+ # Args:
18
+ # query: The search query or topic to look up on the web.
19
+ # num_results: The number of top search results to return (default is 3).
20
 
21
+ # Returns:
22
+ # A string containing summarized up-to-date information from the web.
23
+ # """
24
+ # try:
25
+ # ddg = DuckDuckGoSearchTool()
26
+ # results = ddg.text(query, max_results=num_results)
27
 
28
+ # if not results:
29
+ # return f"No results found for '{query}'."
30
 
31
+ # info_list = []
32
+ # for i, r in enumerate(results):
33
+ # title = r.get("title", "No title")
34
+ # body = r.get("body", "No summary available.")
35
+ # link = r.get("href", "")
36
+ # info_list.append(f"{i+1}. {title}\n{body}\n({link})")
37
 
38
+ # return f"Here are the top {num_results} results for '{query}':\n\n" + "\n\n".join(info_list)
39
 
40
+ # except Exception as e:
41
+ # return f"Error performing web search for '{query}': {str(e)}"
42
 
43
 
44
 
 
74
  # Import tool from Hub
75
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
76
 
77
+ web_agent = DuckDuckGoSearchTool()
78
+
79
  with open("prompts.yaml", 'r') as stream:
80
  prompt_templates = yaml.safe_load(stream)
81
 
82
  agent = CodeAgent(
83
  model=model,
84
+ tools=[final_answer, get_current_time_in_timezone, web_agent], ## add your tools here (don't remove final answer)
85
  max_steps=6,
86
  verbosity_level=1,
87
  grammar=None,