GuillaumeProjects commited on
Commit
409f295
·
verified ·
1 Parent(s): 9387515

Update app.py

Browse files

Correcting again search_web tool

Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -14,8 +14,22 @@ def search_web(query:str)-> str: #it's import to specify the return type
14
  Args:
15
  query: the query to search the web
16
  """
17
- web_search_tool = DuckDuckGoSearchTool(max_results=5, rate_limit=2.0)
18
- return web_search_tool(query)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
 
21
  @tool
 
14
  Args:
15
  query: the query to search the web
16
  """
17
+ try:
18
+ web_search_tool = DuckDuckGoSearchTool(max_results=5, rate_limit=2.0)
19
+ results = web_search_tool(query)
20
+
21
+ if not results:
22
+ return "No results found."
23
+
24
+ # Format results into readable text
25
+ formatted = "\n".join(
26
+ [f"{i+1}. {r.get('title', 'No title')} - {r.get('link', 'No link')}\n{r.get('snippet', '')}"
27
+ for i, r in enumerate(results)]
28
+ )
29
+ return formatted
30
+
31
+ except Exception as e:
32
+ return f"Error during web search: {str(e)}"
33
 
34
 
35
  @tool