Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,6 +31,31 @@ def difference_of_two_numbers(arg1:int, arg2:int)-> int:
|
|
| 31 |
diff = arg1 - arg2
|
| 32 |
return diff
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
@tool
|
| 35 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 36 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -50,7 +75,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
model = HfApiModel(
|
| 52 |
max_tokens=2096,
|
| 53 |
-
temperature=0,
|
| 54 |
model_id='meta-llama/Meta-Llama-3-8B-Instruct',
|
| 55 |
custom_role_conversions=None,
|
| 56 |
)
|
|
@@ -62,10 +87,16 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 62 |
with open("prompts.yaml", 'r') as stream:
|
| 63 |
prompt_templates = yaml.safe_load(stream)
|
| 64 |
|
|
|
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
-
tools=[
|
| 68 |
max_steps=6,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
prompt_templates=prompt_templates
|
| 70 |
)
|
| 71 |
|
|
|
|
| 31 |
diff = arg1 - arg2
|
| 32 |
return diff
|
| 33 |
|
| 34 |
+
@tool
|
| 35 |
+
def nse_stock_price_tool(stock_ticker:str)-> str:
|
| 36 |
+
"""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).
|
| 37 |
+
example: 'RELIANCE.NS'
|
| 38 |
+
Args:
|
| 39 |
+
stock_ticker: The stock ticker/symbol for the stock listed in NSE. The exact string input needs to be provided to the function.
|
| 40 |
+
Returns:
|
| 41 |
+
result_string: A string containing the stock_ticker along with the amount in Rupees.
|
| 42 |
+
example: "RELIANCE NS: 1237.22 Rupees."
|
| 43 |
+
"""
|
| 44 |
+
try:
|
| 45 |
+
import math
|
| 46 |
+
import yfinance as yf
|
| 47 |
+
stock_symbol = stock_ticker
|
| 48 |
+
data = yf.download(tickers=stock_symbol, period='1d', interval='1m')
|
| 49 |
+
if len(data):
|
| 50 |
+
latest_data = data.tail(1)
|
| 51 |
+
latest_price = latest_data['Close'].values[0]
|
| 52 |
+
return (f"{stock_symbol}: {round(latest_price, 2)} Rupees.")
|
| 53 |
+
else:
|
| 54 |
+
return "INVALID TICKER/STOCK"
|
| 55 |
+
except Exception as e:
|
| 56 |
+
traceback.print_exc()
|
| 57 |
+
return "INVALID REQUEST"
|
| 58 |
+
|
| 59 |
@tool
|
| 60 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 61 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 75 |
final_answer = FinalAnswerTool()
|
| 76 |
model = HfApiModel(
|
| 77 |
max_tokens=2096,
|
| 78 |
+
temperature=0.5,
|
| 79 |
model_id='meta-llama/Meta-Llama-3-8B-Instruct',
|
| 80 |
custom_role_conversions=None,
|
| 81 |
)
|
|
|
|
| 87 |
with open("prompts.yaml", 'r') as stream:
|
| 88 |
prompt_templates = yaml.safe_load(stream)
|
| 89 |
|
| 90 |
+
|
| 91 |
agent = CodeAgent(
|
| 92 |
model=model,
|
| 93 |
+
tools=[nse_stock_price_tool, final_answer], ## add your tools here (don't remove final answer)
|
| 94 |
max_steps=6,
|
| 95 |
+
verbosity_level=1,
|
| 96 |
+
grammar=None,
|
| 97 |
+
planning_interval=None,
|
| 98 |
+
name=None,
|
| 99 |
+
description=None,
|
| 100 |
prompt_templates=prompt_templates
|
| 101 |
)
|
| 102 |
|