Update components/chat.py
Browse files- components/chat.py +8 -37
components/chat.py
CHANGED
|
@@ -9,12 +9,6 @@ def display_chat_interface():
|
|
| 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):
|
|
@@ -26,50 +20,27 @@ def display_chat_interface():
|
|
| 26 |
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 27 |
try:
|
| 28 |
with st.spinner("Analyzing documents..."):
|
| 29 |
-
#
|
| 30 |
human_message = HumanMessage(content=prompt)
|
| 31 |
-
st.session_state.messages.append(human_message)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
st.
|
| 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)
|
| 61 |
-
|
| 62 |
-
# Force refresh to show new messages
|
| 63 |
st.rerun()
|
| 64 |
else:
|
| 65 |
st.error("No valid response received")
|
| 66 |
|
| 67 |
except Exception as e:
|
| 68 |
-
st.error(f"Error
|
|
|
|
| 69 |
import traceback
|
| 70 |
-
st.error(
|
| 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))
|
|
|
|
| 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):
|
|
|
|
| 20 |
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 21 |
try:
|
| 22 |
with st.spinner("Analyzing documents..."):
|
| 23 |
+
# Create message objects
|
| 24 |
human_message = HumanMessage(content=prompt)
|
|
|
|
| 25 |
|
| 26 |
+
# Add to chat history
|
| 27 |
+
st.session_state.messages.append(human_message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Get response
|
| 30 |
response = st.session_state.qa_system.invoke({
|
| 31 |
"input": prompt,
|
| 32 |
+
"chat_history": list(st.session_state.messages) # Ensure it's a list
|
| 33 |
})
|
| 34 |
|
| 35 |
if response:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
ai_message = AIMessage(content=str(response))
|
| 37 |
st.session_state.messages.append(ai_message)
|
|
|
|
|
|
|
| 38 |
st.rerun()
|
| 39 |
else:
|
| 40 |
st.error("No valid response received")
|
| 41 |
|
| 42 |
except Exception as e:
|
| 43 |
+
st.error(f"Error: {e}")
|
| 44 |
+
st.error(f"Error type: {type(e)}")
|
| 45 |
import traceback
|
| 46 |
+
st.error(traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|