Arcpolar commited on
Commit
3e98138
·
verified ·
1 Parent(s): a231c1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -48,6 +48,37 @@ def fact_checker(claim:str)-> str: #it's import to specify the return type
48
  return f"Error during fact-checking: {str(e)}"
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  @tool
52
  def get_current_time_in_timezone(timezone: str) -> str:
53
  """A tool that fetches the current local time in a specified timezone.
@@ -85,7 +116,7 @@ with open("prompts.yaml", 'r') as stream:
85
 
86
  agent = CodeAgent(
87
  model=model,
88
- tools=[fact_checker, get_current_time_in_timezone, image_generation_tool, final_answer], ## add your tools here (don't remove final answer)
89
  max_steps=6,
90
  verbosity_level=1,
91
  grammar=None,
 
48
  return f"Error during fact-checking: {str(e)}"
49
 
50
 
51
+ @tool
52
+ def stock_price(symbol: str) -> str:
53
+ """A tool that retrieves the current stock price for a given stock symbol.
54
+ Args:
55
+ symbol: The ticker symbol of the stock (e.g., AAPL for Apple Inc.).
56
+ Returns:
57
+ A summary indicating the current price of the stock or an error message if unavailable.
58
+ """
59
+ try:
60
+ import yfinance as yf
61
+
62
+ # Initialize the ticker for the given symbol
63
+ ticker = yf.Ticker(symbol)
64
+
65
+ # Try to get the current price from the ticker info
66
+ price = ticker.info.get("currentPrice")
67
+
68
+ # Fallback: if 'currentPrice' is not available, get the last closing price
69
+ if price is None:
70
+ history = ticker.history(period="1d")
71
+ if not history.empty:
72
+ price = history["Close"].iloc[-1]
73
+ else:
74
+ return f"Could not retrieve the current price for {symbol}. Please verify the ticker symbol."
75
+
76
+ # Return the current price in a formatted string
77
+ return f"The current price for {symbol} is ${price:.2f}."
78
+
79
+ except Exception as e:
80
+ return f"An error occurred while retrieving the stock price for {symbol}: {e}"
81
+
82
  @tool
83
  def get_current_time_in_timezone(timezone: str) -> str:
84
  """A tool that fetches the current local time in a specified timezone.
 
116
 
117
  agent = CodeAgent(
118
  model=model,
119
+ tools=[fact_checker, stock_price, get_current_time_in_timezone, image_generation_tool, final_answer], ## add your tools here (don't remove final answer)
120
  max_steps=6,
121
  verbosity_level=1,
122
  grammar=None,