Spaces:
Paused
Paused
Update components/chat.py
Browse files- components/chat.py +10 -25
components/chat.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
# components/chat.py
|
| 2 |
import streamlit as st
|
| 3 |
-
from langchain_core.messages import HumanMessage, AIMessage
|
| 4 |
-
from utils.database import format_chat_history # Import the formatting function
|
| 5 |
|
| 6 |
def display_chat_interface():
|
| 7 |
"""Display chat interface component"""
|
|
@@ -9,9 +8,7 @@ def display_chat_interface():
|
|
| 9 |
|
| 10 |
# Initialize chat history if not exists
|
| 11 |
if 'chat_history' not in st.session_state:
|
| 12 |
-
st.session_state.chat_history = [
|
| 13 |
-
SystemMessage(content="Chat started. You can ask questions about the RFP documents.")
|
| 14 |
-
]
|
| 15 |
|
| 16 |
# Display chat history
|
| 17 |
for message in st.session_state.chat_history:
|
|
@@ -19,34 +16,22 @@ def display_chat_interface():
|
|
| 19 |
st.markdown(f"🧑💼 **You**: {message.content}")
|
| 20 |
elif isinstance(message, AIMessage):
|
| 21 |
st.markdown(f"🤖 **Assistant**: {message.content}")
|
| 22 |
-
# Don't display system messages in the UI
|
| 23 |
|
| 24 |
# Chat input
|
| 25 |
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 26 |
try:
|
| 27 |
with st.spinner("Analyzing documents..."):
|
| 28 |
-
# Add
|
| 29 |
-
|
| 30 |
-
st.session_state.chat_history.append(current_msg)
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
"input": prompt,
|
| 38 |
-
"chat_history": formatted_history
|
| 39 |
-
})
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
ai_msg = AIMessage(content=result['answer'])
|
| 44 |
-
st.session_state.chat_history.append(ai_msg)
|
| 45 |
-
|
| 46 |
-
# Rerun to update the display
|
| 47 |
-
st.rerun()
|
| 48 |
-
else:
|
| 49 |
-
st.error("No valid response received from the QA system")
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
st.error(f"Error generating response: {e}")
|
|
|
|
| 1 |
# components/chat.py
|
| 2 |
import streamlit as st
|
| 3 |
+
from langchain_core.messages import HumanMessage, AIMessage
|
|
|
|
| 4 |
|
| 5 |
def display_chat_interface():
|
| 6 |
"""Display chat interface component"""
|
|
|
|
| 8 |
|
| 9 |
# Initialize chat history if not exists
|
| 10 |
if 'chat_history' not in st.session_state:
|
| 11 |
+
st.session_state.chat_history = []
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Display chat history
|
| 14 |
for message in st.session_state.chat_history:
|
|
|
|
| 16 |
st.markdown(f"🧑💼 **You**: {message.content}")
|
| 17 |
elif isinstance(message, AIMessage):
|
| 18 |
st.markdown(f"🤖 **Assistant**: {message.content}")
|
|
|
|
| 19 |
|
| 20 |
# Chat input
|
| 21 |
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 22 |
try:
|
| 23 |
with st.spinner("Analyzing documents..."):
|
| 24 |
+
# Add user message to history
|
| 25 |
+
st.session_state.chat_history.append(HumanMessage(content=prompt))
|
|
|
|
| 26 |
|
| 27 |
+
# Run the agent
|
| 28 |
+
response = st.session_state.qa_system.run(prompt)
|
| 29 |
|
| 30 |
+
# Add AI response to history
|
| 31 |
+
st.session_state.chat_history.append(AIMessage(content=response))
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# Force refresh to show new messages
|
| 34 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
st.error(f"Error generating response: {e}")
|