ValentinGuigon commited on
Commit
5258231
·
verified ·
1 Parent(s): 9f39c86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -8,15 +8,38 @@ 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 my_custom_tool(arg1:str, arg2:int)-> 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 does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
+ # Edit: now updated to conduct a web search
12
+
13
  @tool
14
+ def make_web_search(query: str) -> str:
15
+ """A tool that conducts a web search using DuckDuckGo
 
16
  Args:
17
+ query: A string representing a valid query for a web search.
18
+ Returns:
19
+ A string containing the search results or an error message.
20
  """
21
+ try:
22
+ # Initialize the DuckDuckGo search tool
23
+ search_tool = DuckDuckGoSearchTool()
24
+
25
+ # Perform the search
26
+ results = search_tool.run(query)
27
+
28
+ # Format the results
29
+ if not results:
30
+ return "No results found for your query."
31
+
32
+ formatted_results = []
33
+ for i, result in enumerate(results[:3], 1): # Show top 3 results
34
+ formatted_results.append(
35
+ f"{i}. {result.get('title', 'No title')}\n"
36
+ f" URL: {result.get('link', 'No URL')}\n"
37
+ f" Description: {result.get('body', 'No description')}\n"
38
+ )
39
+
40
+ return f"Web search results for '{query}':\n" + "\n".join(formatted_results)
41
+ except Exception as e:
42
+ return f"Error performing web search: {str(e)}"
43
 
44
  @tool
45
  def get_current_time_in_timezone(timezone: str) -> str: