Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,11 +37,10 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 37 |
@tool
|
| 38 |
def get_current_price(ticker_symbol: str) -> float:
|
| 39 |
"""
|
| 40 |
-
A tool that fetches the latest stock
|
| 41 |
|
| 42 |
Args:
|
| 43 |
ticker_symbol (str): The stock ticker symbol (e.g., "AAPL" for Apple, "GOOGL" for Google).
|
| 44 |
-
- This is the unique identifier for the stock you want to fetch data for.
|
| 45 |
|
| 46 |
Returns:
|
| 47 |
float: The current stock price of the given ticker symbol.
|
|
@@ -50,14 +49,16 @@ def get_current_price(ticker_symbol: str) -> float:
|
|
| 50 |
>>> get_current_price("AAPL")
|
| 51 |
150.25
|
| 52 |
"""
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
final_answer = FinalAnswerTool()
|
| 63 |
|
|
|
|
| 37 |
@tool
|
| 38 |
def get_current_price(ticker_symbol: str) -> float:
|
| 39 |
"""
|
| 40 |
+
A tool that fetches the latest stock price for a given stock ticker.
|
| 41 |
|
| 42 |
Args:
|
| 43 |
ticker_symbol (str): The stock ticker symbol (e.g., "AAPL" for Apple, "GOOGL" for Google).
|
|
|
|
| 44 |
|
| 45 |
Returns:
|
| 46 |
float: The current stock price of the given ticker symbol.
|
|
|
|
| 49 |
>>> get_current_price("AAPL")
|
| 50 |
150.25
|
| 51 |
"""
|
| 52 |
+
try:
|
| 53 |
+
# Fetch the stock data using yfinance
|
| 54 |
+
stock = yf.Ticker(ticker_symbol)
|
| 55 |
+
|
| 56 |
+
# Get the current price (the last close price)
|
| 57 |
+
current_price = stock.history(period="1d")['Close'].iloc[0]
|
| 58 |
+
|
| 59 |
+
return float(current_price)
|
| 60 |
+
except Exception as e:
|
| 61 |
+
return f"Error fetching price for {ticker_symbol}: {str(e)}"
|
| 62 |
|
| 63 |
final_answer = FinalAnswerTool()
|
| 64 |
|