Cheangys commited on
Commit
2bc5bf0
·
verified ·
1 Parent(s): ea0a3f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -48,7 +48,7 @@ def get_stock_price(stock: str) -> str:
48
  search_tool = DuckDuckGoSearchTool()
49
 
50
  # Perform the search query
51
- search_results = search_tool.run(f"Current stock price of {stock}")
52
 
53
  # If search_results is a list, extract the first relevant result
54
  if isinstance(search_results, list) and len(search_results) > 0:
@@ -58,6 +58,32 @@ def get_stock_price(stock: str) -> str:
58
 
59
  except Exception as e:
60
  return f"Error fetching price for stock '{stock}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
 
63
 
 
48
  search_tool = DuckDuckGoSearchTool()
49
 
50
  # Perform the search query
51
+ search_results = search_tool.run(f"what is the current price of {stock}?")
52
 
53
  # If search_results is a list, extract the first relevant result
54
  if isinstance(search_results, list) and len(search_results) > 0:
 
58
 
59
  except Exception as e:
60
  return f"Error fetching price for stock '{stock}': {str(e)}"
61
+
62
+ @tool
63
+ def web_search(query: str) -> str:
64
+ """Fetches the result from a web search.
65
+
66
+ Args:
67
+ stock: A string representing a query or question.
68
+
69
+ Returns:
70
+ A string with the answer of the search.
71
+ """
72
+ try:
73
+ # Initialize the search tool
74
+ search_tool = DuckDuckGoSearchTool()
75
+
76
+ # Perform the search query
77
+ search_results = search_tool.run(query)
78
+
79
+ # If search_results is a list, extract the first relevant result
80
+ if isinstance(search_results, list) and len(search_results) > 0:
81
+ return {search_results[0]}"
82
+
83
+ return f"Could not find {stock}. Please try again."
84
+
85
+ except Exception as e:
86
+ return f"Error finding '{stock}': {str(e)}"
87
 
88
 
89