Cheangys commited on
Commit
74c39c8
·
verified ·
1 Parent(s): 60df814

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -59,9 +59,10 @@ def get_stock_price(stock: str) -> str:
59
  except Exception as e:
60
  return f"Error fetching price for stock '{stock}': {str(e)}"
61
 
 
62
 
63
  @tool
64
- def web_search(query: str) -> str:
65
  """
66
  Fetches the result from a web search using DuckDuckGo.
67
 
@@ -69,19 +70,19 @@ def web_search(query: str) -> str:
69
  query (str): A search query or question.
70
 
71
  Returns:
72
- str: The top search result as a string.
73
  """
74
  try:
75
  search_tool = DuckDuckGoSearchTool()
76
  search_results = search_tool.run(query)
77
 
78
  if isinstance(search_results, list) and len(search_results) > 0:
79
- return f"Top result for '{query}': {search_results[0]}"
80
 
81
- return f"No results found for '{query}'."
82
 
83
  except Exception as e:
84
- return f"Error during search: {str(e)}"
85
 
86
 
87
  final_answer = FinalAnswerTool()
 
59
  except Exception as e:
60
  return f"Error fetching price for stock '{stock}': {str(e)}"
61
 
62
+ from typing import Dict
63
 
64
  @tool
65
+ def web_search(query: str) -> Dict[str, str]:
66
  """
67
  Fetches the result from a web search using DuckDuckGo.
68
 
 
70
  query (str): A search query or question.
71
 
72
  Returns:
73
+ Dict[str, str]: A dictionary with either the result or an error message.
74
  """
75
  try:
76
  search_tool = DuckDuckGoSearchTool()
77
  search_results = search_tool.run(query)
78
 
79
  if isinstance(search_results, list) and len(search_results) > 0:
80
+ return {"query": query, "result": search_results[0]}
81
 
82
+ return {"query": query, "error": "No results found."}
83
 
84
  except Exception as e:
85
+ return {"query": query, "error": f"Error during search: {str(e)}"}
86
 
87
 
88
  final_answer = FinalAnswerTool()