T-K-O-H commited on
Commit
878dd56
Β·
1 Parent(s): 10c3afe

Update sessions

Browse files
Files changed (2) hide show
  1. app.py +24 -9
  2. tools.py +8 -0
app.py CHANGED
@@ -33,17 +33,29 @@ async def start_chat():
33
  # Initialize empty chat history for this session
34
  chat_histories[session_id] = []
35
 
36
- welcome_message = """πŸ‘‹ Welcome to the Stock Price Calculator!
37
 
38
- I can help you with:
39
- β€’ Getting real-time stock prices
40
- β€’ Calculating how many shares you can buy
41
 
42
- Try these examples:
43
- β€’ Type 'AAPL' to get Apple's stock price
44
- β€’ Ask 'How many MSFT shares can I buy with $10000?'
45
 
46
- What would you like to know?"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  await cl.Message(content=welcome_message).send()
49
 
@@ -71,7 +83,9 @@ async def handle_message(message: cl.Message):
71
  }
72
 
73
  # Process the message with agent_node
 
74
  response = agent_node(state)
 
75
 
76
  # Send the response back to the user
77
  if isinstance(response, dict) and "output" in response:
@@ -79,13 +93,14 @@ async def handle_message(message: cl.Message):
79
  history.append({"role": "assistant", "content": response["output"]})
80
  await cl.Message(content=response["output"]).send()
81
  else:
 
82
  await cl.Message(content="Received an invalid response format from the agent.").send()
83
 
84
  # Update history in storage
85
  chat_histories[session_id] = history
86
 
87
  except Exception as e:
88
- print(f"Error occurred: {e}")
89
  await cl.Message(content="Sorry, something went wrong while processing your request.").send()
90
 
91
  @cl.on_chat_end
 
33
  # Initialize empty chat history for this session
34
  chat_histories[session_id] = []
35
 
36
+ welcome_message = """πŸ“ˆ Welcome to the AI Stock Assistant!
37
 
38
+ I'm your intelligent stock market companion. Here's what I can do:
 
 
39
 
40
+ 1. Get Real-Time Stock Prices πŸ“Š
41
+ β€’ Just type a ticker symbol (e.g., 'AAPL' for Apple)
42
+ β€’ Or ask naturally (e.g., "What's Microsoft's stock price?")
43
 
44
+ 2. Calculate Share Purchases πŸ’°
45
+ β€’ Ask how many shares you can buy (e.g., "How many TSLA shares for $5000?")
46
+ β€’ I'll show you the current price and number of shares
47
+
48
+ 3. Smart Features 🧠
49
+ β€’ I understand company names and ticker symbols
50
+ β€’ I remember context from previous messages
51
+ β€’ I support all major stock exchanges
52
+
53
+ Popular stocks to try:
54
+ β€’ Tech: AAPL (Apple), MSFT (Microsoft), GOOGL (Google)
55
+ β€’ Finance: JPM (JPMorgan), BAC (Bank of America)
56
+ β€’ Retail: WMT (Walmart), COST (Costco)
57
+
58
+ What would you like to know about the stock market?"""
59
 
60
  await cl.Message(content=welcome_message).send()
61
 
 
83
  }
84
 
85
  # Process the message with agent_node
86
+ print(f"[Debug] Processing message: {message.content}")
87
  response = agent_node(state)
88
+ print(f"[Debug] Agent response: {response}")
89
 
90
  # Send the response back to the user
91
  if isinstance(response, dict) and "output" in response:
 
93
  history.append({"role": "assistant", "content": response["output"]})
94
  await cl.Message(content=response["output"]).send()
95
  else:
96
+ print(f"[Debug] Invalid response format: {response}")
97
  await cl.Message(content="Received an invalid response format from the agent.").send()
98
 
99
  # Update history in storage
100
  chat_histories[session_id] = history
101
 
102
  except Exception as e:
103
+ print(f"[Debug] Error occurred: {e}")
104
  await cl.Message(content="Sorry, something went wrong while processing your request.").send()
105
 
106
  @cl.on_chat_end
tools.py CHANGED
@@ -7,18 +7,26 @@ def get_price(ticker):
7
  try:
8
  # Clean the ticker symbol
9
  ticker = ticker.strip().upper()
 
 
10
  stock = yf.Ticker(ticker)
 
11
 
12
  # Get the stock info
13
  info = stock.info
 
 
14
  if 'regularMarketPrice' not in info or info['regularMarketPrice'] is None:
 
15
  return f"Could not get the current price for {ticker}. Please verify the ticker symbol."
16
 
17
  price = info['regularMarketPrice']
18
  company_name = info.get('longName', ticker)
 
19
 
20
  return f"The current price of {company_name} ({ticker}) is ${price:.2f}"
21
  except Exception as e:
 
22
  return f"Error getting price for {ticker}: {str(e)}"
23
 
24
  def buying_power_tool(query):
 
7
  try:
8
  # Clean the ticker symbol
9
  ticker = ticker.strip().upper()
10
+ print(f"[Debug] Fetching price for ticker: {ticker}")
11
+
12
  stock = yf.Ticker(ticker)
13
+ print(f"[Debug] Created yfinance Ticker object for {ticker}")
14
 
15
  # Get the stock info
16
  info = stock.info
17
+ print(f"[Debug] Retrieved stock info: {info}")
18
+
19
  if 'regularMarketPrice' not in info or info['regularMarketPrice'] is None:
20
+ print(f"[Debug] No regularMarketPrice found for {ticker}")
21
  return f"Could not get the current price for {ticker}. Please verify the ticker symbol."
22
 
23
  price = info['regularMarketPrice']
24
  company_name = info.get('longName', ticker)
25
+ print(f"[Debug] Found price for {company_name} ({ticker}): ${price}")
26
 
27
  return f"The current price of {company_name} ({ticker}) is ${price:.2f}"
28
  except Exception as e:
29
+ print(f"[Debug] Error in get_price for {ticker}: {str(e)}")
30
  return f"Error getting price for {ticker}: {str(e)}"
31
 
32
  def buying_power_tool(query):