JC-Hug commited on
Commit
c46acaf
·
1 Parent(s): 2c839fb

Added duckduckgo search engine

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -7,6 +7,21 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ @tool
11
+ def duckduckgo_search(query: str, max_results: int = 5) -> str:
12
+ """A tool that searches the web.
13
+ Args:
14
+ query: The search query string.
15
+ max_results: The number of search results to return (default: 5).
16
+ """
17
+ try:
18
+ search_tool = DuckDuckGoSearchTool()
19
+ results = search_tool.run(query, num_results=max_results)
20
+ formatted_results = "\n".join([f"{i+1}. {res}" for i, res in enumerate(results)])
21
+ return f"Top {max_results} results for '{query}':\n{formatted_results}"
22
+ except Exception as e:
23
+ return f"Error performing search: {str(e)}"
24
+
25
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
26
  @tool
27
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type