Spaces:
Sleeping
Sleeping
Create a tool of getting the stock price given the ticker symbol
Browse filesAlso add `get_stock_price` and `get_current_time_in_timezone` in the `tools` list.
app.py
CHANGED
|
@@ -3,20 +3,27 @@ import datetime
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
#
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +62,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[search_tool, final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import yfinance as yf
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
+
# Tool of getting the stock price for a given stock symbol
|
| 12 |
@tool
|
| 13 |
+
def get_stock_price(stock_symbol: str)-> str:
|
| 14 |
+
"""A tool that get the stock price for a given stock symbol by using the Yahoo Finance API.
|
|
|
|
| 15 |
Args:
|
| 16 |
+
stock_symbol: stock ticker symbol which is typically 1 to 5 letters long and is used to
|
| 17 |
+
identify a publicly traded company's shares on a stock exchange, e.g., MSFT, AMZN.
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
current stock price in dollars.
|
| 21 |
"""
|
| 22 |
+
ticker = yf.Ticker(stock_symbol.upper())
|
| 23 |
+
price = ticker.info["regularMarketPrice"]
|
| 24 |
+
return f"The current stock price of {symbol.upper()} is ${price:.2f}."
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return f"Failed to retrieve stock price for {symbol}: {str(e)}"
|
| 27 |
|
| 28 |
@tool
|
| 29 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 62 |
|
| 63 |
agent = CodeAgent(
|
| 64 |
model=model,
|
| 65 |
+
tools=[get_stock_price, get_current_time_in_timezone, search_tool, final_answer], ## add your tools here (don't remove final answer)
|
| 66 |
max_steps=6,
|
| 67 |
verbosity_level=1,
|
| 68 |
grammar=None,
|