Tomjonesuk commited on
Commit
b257acf
·
verified ·
1 Parent(s): a184c0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -44,26 +44,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
44
 
45
  @tool
46
  def web_search(query: str) -> str:
47
- """Searches the internet for information.
48
- If the search fails, do not repeatedly retry it.
 
49
  Args:
50
  query: The search terms to look up.
51
  """
52
- try:
53
- results = DDGS().text(query, max_results=5)
54
 
55
- print("SEARCH QUERY:", query)
56
- print("SEARCH RESULTS:", results)
 
57
 
58
- if not results:
59
- return "No results found. Do not retry."
 
 
 
60
 
61
- return str(results)
 
 
 
62
 
63
- except Exception as e:
64
- print("SEARCH ERROR:", repr(e))
65
- return f"Search failed: {e}. Do not retry."
66
 
 
67
 
68
  final_answer = FinalAnswerTool()
69
 
 
44
 
45
  @tool
46
  def web_search(query: str) -> str:
47
+ """Searches the internet using keywords.
48
+ Returns relevant results with URLs.
49
+ Do not use this tool to open a specific webpage.
50
  Args:
51
  query: The search terms to look up.
52
  """
 
 
53
 
54
+ for engine in ["brave", "duckduckgo", "yahoo", "mojeek"]:
55
+ try:
56
+ print(f"Searching {engine}: {query}")
57
 
58
+ results = DDGS().text(
59
+ query,
60
+ max_results=5,
61
+ backend=engine
62
+ )
63
 
64
+ if results:
65
+ print(f"SUCCESS: {engine}")
66
+ print(results)
67
+ return str(results)
68
 
69
+ except Exception as e:
70
+ print(f"FAILED: {engine}: {e}")
 
71
 
72
+ return "All search engines failed. Search unavailable."
73
 
74
  final_answer = FinalAnswerTool()
75