FabianHildebrandt commited on
Commit
c7544b0
·
verified ·
1 Parent(s): ae41d02

Added yfinance agent

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -33,6 +34,18 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  final_answer = FinalAnswerTool()
37
  model = HfApiModel(
38
  max_tokens=2096,
@@ -50,7 +63,7 @@ with open("prompts.yaml", 'r') as stream:
50
 
51
  agent = CodeAgent(
52
  model=model,
53
- tools=[final_answer, get_current_time_in_timezone, modify_agent_description], ## add your tools here (don't remove final answer)
54
  max_steps=6,
55
  verbosity_level=1,
56
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import yfinance as yf
8
 
9
  from Gradio_UI import GradioUI
10
 
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+ @tool
38
+ def get_yfinance_ticker_price(ticker_name: str) -> float:
39
+ """A tool to return the current price for the provided Yahoo Finance stock ticker name
40
+ Args:
41
+ ticker_name (str): Ticker name. A ticker is the name of a stock in the Yahoo Finance Portal (e. g. Intel Corporation has the ticker INTC)
42
+
43
+ """
44
+ # Get the ticker for the provided ticker name
45
+ ticker = yf.Ticker(ticker_name)
46
+
47
+ return ticker.info.get('regularMarketPrice', None)
48
+
49
  final_answer = FinalAnswerTool()
50
  model = HfApiModel(
51
  max_tokens=2096,
 
63
 
64
  agent = CodeAgent(
65
  model=model,
66
+ tools=[final_answer, get_current_time_in_timezone, modify_agent_description, get_yfinance_ticker_price], ## add your tools here (don't remove final answer)
67
  max_steps=6,
68
  verbosity_level=1,
69
  grammar=None,