Add NSE price sourcing tool
Browse files
app.py
CHANGED
@@ -19,6 +19,32 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Writing my first custom tool
|
23 |
@tool
|
24 |
def toss_a_die(k: int) -> int:
|
@@ -51,6 +77,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
51 |
|
52 |
|
53 |
final_answer = FinalAnswerTool()
|
|
|
54 |
model = HfApiModel(
|
55 |
max_tokens=1048,
|
56 |
temperature=0.5,
|
|
|
19 |
"""
|
20 |
return "What magic will you build ?"
|
21 |
|
22 |
+
## Copied from https://huggingface.co/spaces/iamnamas/nse_stockprice_agent
|
23 |
+
@tool
|
24 |
+
def nse_stock_price_tool(stock_ticker:str)-> str:
|
25 |
+
"""A tool that is used to retrieve the latest closing price of a stock based on the stock ticker from the Indian Stock Exchange (NSE).
|
26 |
+
example: 'RELIANCE.NS'
|
27 |
+
Args:
|
28 |
+
stock_ticker: The stock ticker/symbol for the stock listed in NSE. The exact string input needs to be provided to the function.
|
29 |
+
Returns:
|
30 |
+
result_string: A string containing the stock_ticker along with the amount in Rupees.
|
31 |
+
example: "RELIANCE NS: 1237.22 Rupees."
|
32 |
+
"""
|
33 |
+
try:
|
34 |
+
import math
|
35 |
+
import yfinance as yf
|
36 |
+
stock_symbol = stock_ticker
|
37 |
+
data = yf.download(tickers=stock_symbol, period='1d', interval='1m')
|
38 |
+
if len(data):
|
39 |
+
latest_data = data.tail(1)
|
40 |
+
latest_price = latest_data['Close'].values[0]
|
41 |
+
return (f"{stock_symbol}: {round(latest_price, 2)} Rupees.")
|
42 |
+
else:
|
43 |
+
return "INVALID TICKER/STOCK"
|
44 |
+
except Exception as e:
|
45 |
+
traceback.print_exc()
|
46 |
+
return "INVALID REQUEST"
|
47 |
+
|
48 |
# Writing my first custom tool
|
49 |
@tool
|
50 |
def toss_a_die(k: int) -> int:
|
|
|
77 |
|
78 |
|
79 |
final_answer = FinalAnswerTool()
|
80 |
+
|
81 |
model = HfApiModel(
|
82 |
max_tokens=1048,
|
83 |
temperature=0.5,
|