Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,16 +35,30 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_stock_price(stock: str) -> str:
|
| 38 |
-
|
|
|
|
| 39 |
Args:
|
| 40 |
-
stock: A string representing a
|
|
|
|
|
|
|
|
|
|
| 41 |
"""
|
| 42 |
try:
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
final_answer = FinalAnswerTool()
|
|
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_stock_price(stock: str) -> str:
|
| 38 |
+
"""Fetches the current stock price using DuckDuckGo search.
|
| 39 |
+
|
| 40 |
Args:
|
| 41 |
+
stock: A string representing a stock ticker or company name (e.g., 'AAPL', 'GOOGL').
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
A string with the stock price or an error message.
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
+
# Initialize the search tool
|
| 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:
|
| 55 |
+
return f"The current price for {stock} is: {search_results[0]}"
|
| 56 |
+
|
| 57 |
+
return f"Could not fetch stock price for {stock}. Please try again."
|
| 58 |
+
|
| 59 |
except Exception as e:
|
| 60 |
return f"Error fetching price for stock '{stock}': {str(e)}"
|
| 61 |
+
|
| 62 |
|
| 63 |
|
| 64 |
final_answer = FinalAnswerTool()
|