ValentinGuigon commited on
Commit
54b30ce
·
verified ·
1 Parent(s): 29cac4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -20,24 +20,14 @@ def web_search(query: str) -> str:
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
 
 
20
  """
21
  try:
22
  # Initialize the DuckDuckGo search tool
23
+ search_tool = DuckDuckGoSearchTool(max_results=max_results)
24
 
25
+ # Perform the search using the forward method
26
+ results = search_tool.forward(query)
27
 
28
+ # Return the formatted results
29
+ return results
30
+
 
 
 
 
 
 
 
 
 
 
31
  except Exception as e:
32
  return f"Error performing web search: {str(e)}"
33