Update app.py
#392
by
gavindias7
- opened
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
|
|
@@ -18,6 +19,26 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
+
import yfinance as yf
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
|
|
|
|
| 19 |
"""
|
| 20 |
return "What magic will you build ?"
|
| 21 |
|
| 22 |
+
# Below is the rool to get the current price of the Stock
|
| 23 |
+
@tool
|
| 24 |
+
def get_stock_price(stock_code: str) -> str:
|
| 25 |
+
"""A tool that Fetches the current stock price for a given stock code.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
stock_code: The stock ticker symbol (e.g., 'NVDA').
|
| 29 |
+
"""
|
| 30 |
+
try:
|
| 31 |
+
ticker = yf.Ticker(stock_code)
|
| 32 |
+
todays_data = ticker.history(period='1d')
|
| 33 |
+
if not todays_data.empty:
|
| 34 |
+
current_price = todays_data['Close'][-1]
|
| 35 |
+
return current_price
|
| 36 |
+
else:
|
| 37 |
+
return None
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"Error fetching stock price for {stock_code}: {e}")
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 44 |
"""A tool that fetches the current local time in a specified timezone.
|