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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -60,10 +60,8 @@ def get_stock_price(stock: str) -> str:
60
  return f"Error fetching price for stock '{stock}': {str(e)}"
61
 
62
 
63
- from typing import Any
64
-
65
  @tool
66
- def web_search(query: str) -> Any:
67
  """
68
  Fetches the result from a web search using DuckDuckGo.
69
 
@@ -71,24 +69,19 @@ def web_search(query: str) -> Any:
71
  query (str): A search query or question.
72
 
73
  Returns:
74
- dict: A dictionary containing the search query and the top result.
75
  """
76
  try:
77
- # Initialize the search tool
78
  search_tool = DuckDuckGoSearchTool()
79
-
80
- # Perform the search query
81
  search_results = search_tool.run(query)
82
-
83
- # If search_results is a list, extract the first relevant result
84
  if isinstance(search_results, list) and len(search_results) > 0:
85
- return {"query": query, "result": search_results[0]}
86
-
87
- return {"query": query, "error": "No results found."}
88
-
89
- except Exception as e:
90
- return {"query": query, "error": f"Error during search: {str(e)}"}
91
 
 
 
92
 
93
 
94
  final_answer = FinalAnswerTool()
 
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
  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()