quantyi commited on
Commit
a466cfd
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files

The get_last_prices tool is designed to fetch the most recent closing price for a specified stock ticker from Yahoo Finance. It utilizes the yfinance library to access intraday market data, retrieving data for the current day at one-minute intervals. Once the data is collected, the tool extracts the last available closing price and returns it as a string. This tool is particularly useful for applications requiring up-to-date market prices for financial analysis or trading purposes.

Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
@@ -9,14 +11,20 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
- Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
1
+ pip install yfinance
2
+ import yfinance
3
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
4
  import datetime
5
  import requests
 
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def get_last_prices(ticker:str)-> str: #it's import to specify the return type
15
  #Keep this format for the description / args / args description but feel free to modify the tool
 
 
 
 
16
  """
17
+ """
18
+ stock = yf.Ticker(ticker)
19
+
20
+ df = stock.history(period ="1d", interval = "1m")
21
+
22
+ if df.empty:
23
+ raise ValueError(f'Nessun dato disponibile per il ticker')
24
+
25
+ last_price = df['Close'].iloc[-1]
26
+
27
+ return str(last_price)
28
 
29
  @tool
30
  def get_current_time_in_timezone(timezone: str) -> str: