iamharisai commited on
Commit
2c6a40c
·
verified ·
1 Parent(s): e5760b2

feat: get_stock_price tool

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -33,6 +33,20 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -55,7 +69,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def get_stock_price(symbol: str) -> str:
38
+ """
39
+ The tool that provides the current stock price for given symbol.
40
+ Args: It will take the stock symbol as a string and return the stock price
41
+ """
42
+ # symbol = 'AAPL'
43
+ api_url = 'https://api.api-ninjas.com/v1/stockprice?ticker={}'.format(symbol)
44
+ response = requests.get(api_url, headers={'X-Api-Key': 'tLxWjj6xXdYXkyajGKBdKQ==ncmATTD1rqr2s2Hb'})
45
+ if response.status_code == requests.codes.ok:
46
+ return (response.json()['price'])
47
+ else:
48
+ print("Error:", response.status_code, response.text)
49
+
50
 
51
  final_answer = FinalAnswerTool()
52
 
 
69
 
70
  agent = CodeAgent(
71
  model=model,
72
+ tools=[final_answer,get_current_time_in_timezone,get_stock_price], ## add your tools here (don't remove final answer)
73
  max_steps=6,
74
  verbosity_level=1,
75
  grammar=None,