lethaq commited on
Commit
9422319
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files

Added the function of searching today's US stock prices and recommended books, including fiction, history, and romance

Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -34,6 +34,33 @@ def get_current_time_in_timezone(timezone: str) -> str:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
 
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
 
37
+ @tool
38
+ def get_something_to_read(booksname:srt) -> str:
39
+ fiction_books = ["To Kill a Mockingbird", "1984", "Pride and Prejudice"]
40
+ history_books = ["Sapiens: A Brief History of Humankind", "The Guns of August", "Guns, Germs, and Steel"]
41
+ romance_books = ["Jane Eyre", "Wuthering Heights", "Outlander"]
42
+
43
+ if "fiction" in user_tip.lower():
44
+ return random.choice(fiction_books)
45
+ elif "history" in user_tip.lower():
46
+ return random.choice(history_books)
47
+ elif "romance" in user_tip.lower():
48
+ return random.choice(romance_books)
49
+ else:
50
+ all_books: List[str] = fiction_books + history_books + romance_books
51
+ return random.choice(all_books)
52
+ @tool
53
+ import yfinance as yf
54
+ def get_today_us_stock_price(ticker_symbol: str) -> str:
55
+ try:
56
+ stock = yf.Ticker(ticker_symbol)
57
+ today_data = stock.history(period="1d")
58
+ close_price = today_data['close'].iloc[-1]
59
+ return f"The today's closing price of {ticker_symbol} is: ${close_price}"
60
+ except Exception as e:
61
+ return f"Error fetching stock price for {ticker_symbol}: {str(e)}"
62
+
63
+
64
  final_answer = FinalAnswerTool()
65
 
66
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder: