cryogenic22 commited on
Commit
5012c5c
·
verified ·
1 Parent(s): b72547c

Update components/chat.py

Browse files
Files changed (1) hide show
  1. components/chat.py +31 -2
components/chat.py CHANGED
@@ -9,6 +9,12 @@ def display_chat_interface():
9
  if 'messages' not in st.session_state:
10
  st.session_state.messages = []
11
 
 
 
 
 
 
 
12
  # Display chat history
13
  for message in st.session_state.messages:
14
  if isinstance(message, HumanMessage):
@@ -24,13 +30,31 @@ def display_chat_interface():
24
  human_message = HumanMessage(content=prompt)
25
  st.session_state.messages.append(human_message)
26
 
27
- # Get response from QA system with chat history
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  response = st.session_state.qa_system.invoke({
29
  "input": prompt,
30
  "chat_history": st.session_state.messages
31
  })
32
 
33
  if response:
 
 
 
 
 
34
  # Add AI message to chat history
35
  ai_message = AIMessage(content=str(response))
36
  st.session_state.messages.append(ai_message)
@@ -43,4 +67,9 @@ def display_chat_interface():
43
  except Exception as e:
44
  st.error(f"Error generating response: {e}")
45
  import traceback
46
- st.error(f"Detailed error: {traceback.format_exc()}")
 
 
 
 
 
 
9
  if 'messages' not in st.session_state:
10
  st.session_state.messages = []
11
 
12
+ # DEBUG: Print current state of messages
13
+ st.write("DEBUG - Current messages in session state:")
14
+ for msg in st.session_state.messages:
15
+ st.write(f"Message type: {type(msg)}")
16
+ st.write(f"Message content: {msg.content}")
17
+
18
  # Display chat history
19
  for message in st.session_state.messages:
20
  if isinstance(message, HumanMessage):
 
30
  human_message = HumanMessage(content=prompt)
31
  st.session_state.messages.append(human_message)
32
 
33
+ # DEBUG: Print message object details
34
+ st.write("DEBUG - New human message:")
35
+ st.write(f"Type: {type(human_message)}")
36
+ st.write(f"Content: {human_message.content}")
37
+ st.write("DEBUG - Current chat history types:")
38
+ st.write([type(msg) for msg in st.session_state.messages])
39
+
40
+ # Get response from QA system
41
+ st.write("DEBUG - About to invoke QA system with these inputs:")
42
+ st.write({
43
+ "input": prompt,
44
+ "chat_history": [str(msg) for msg in st.session_state.messages]
45
+ })
46
+
47
  response = st.session_state.qa_system.invoke({
48
  "input": prompt,
49
  "chat_history": st.session_state.messages
50
  })
51
 
52
  if response:
53
+ # DEBUG: Print response details
54
+ st.write("DEBUG - Response received:")
55
+ st.write(f"Response type: {type(response)}")
56
+ st.write(f"Response content: {response}")
57
+
58
  # Add AI message to chat history
59
  ai_message = AIMessage(content=str(response))
60
  st.session_state.messages.append(ai_message)
 
67
  except Exception as e:
68
  st.error(f"Error generating response: {e}")
69
  import traceback
70
+ st.error(f"Detailed error: {traceback.format_exc()}")
71
+
72
+ # DEBUG: Print the state when error occurs
73
+ st.write("DEBUG - State at error:")
74
+ st.write("Messages types:", [type(msg) for msg in st.session_state.messages])
75
+ st.write("QA system type:", type(st.session_state.qa_system))