Spaces:
Paused
Paused
Update components/chat.py
Browse files- components/chat.py +16 -12
components/chat.py
CHANGED
|
@@ -3,34 +3,39 @@ from langchain_core.messages import HumanMessage, AIMessage
|
|
| 3 |
from utils.database import verify_vector_store
|
| 4 |
|
| 5 |
def display_chat_interface():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""Display chat interface component"""
|
| 7 |
st.markdown("### ๐ฌ RFP Analysis Chat")
|
| 8 |
|
| 9 |
-
# Initialize chat history if not exists
|
| 10 |
if 'messages' not in st.session_state:
|
| 11 |
st.session_state.messages = []
|
| 12 |
|
| 13 |
-
# Display chat history
|
| 14 |
for message in st.session_state.messages:
|
| 15 |
if isinstance(message, HumanMessage):
|
| 16 |
st.markdown(f"๐งโ๐ผ **You**: {message.content}")
|
| 17 |
elif isinstance(message, AIMessage):
|
| 18 |
st.markdown(f"๐ค **Assistant**: {message.content}")
|
| 19 |
|
| 20 |
-
|
| 21 |
-
if prompt := st.chat_input("Ask about the RFPs..."):
|
| 22 |
try:
|
| 23 |
with st.spinner("Analyzing documents..."):
|
| 24 |
-
# Create message objects
|
| 25 |
human_message = HumanMessage(content=prompt)
|
| 26 |
-
|
| 27 |
-
# Add to chat history
|
| 28 |
st.session_state.messages.append(human_message)
|
| 29 |
|
| 30 |
-
# Get response
|
| 31 |
response = st.session_state.qa_system.invoke({
|
| 32 |
"input": prompt,
|
| 33 |
-
"chat_history": list(st.session_state.messages)
|
| 34 |
})
|
| 35 |
|
| 36 |
if response:
|
|
@@ -39,9 +44,8 @@ def display_chat_interface():
|
|
| 39 |
st.rerun()
|
| 40 |
else:
|
| 41 |
st.error("No valid response received")
|
| 42 |
-
|
| 43 |
except Exception as e:
|
| 44 |
st.error(f"Error: {e}")
|
| 45 |
-
st.error(f"Error type: {type(e)}")
|
| 46 |
import traceback
|
| 47 |
-
st.error(traceback.format_exc())
|
|
|
|
|
|
| 3 |
from utils.database import verify_vector_store
|
| 4 |
|
| 5 |
def display_chat_interface():
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Check if vector store exists and is properly loaded
|
| 9 |
+
if 'vector_store' not in st.session_state:
|
| 10 |
+
st.warning("๐ Please upload documents first.")
|
| 11 |
+
return
|
| 12 |
+
|
| 13 |
+
# Verify vector store has documents
|
| 14 |
+
if not verify_vector_store(st.session_state.vector_store):
|
| 15 |
+
st.warning("โ Documents are still being processed. Please wait...")
|
| 16 |
+
return
|
| 17 |
+
|
| 18 |
"""Display chat interface component"""
|
| 19 |
st.markdown("### ๐ฌ RFP Analysis Chat")
|
| 20 |
|
|
|
|
| 21 |
if 'messages' not in st.session_state:
|
| 22 |
st.session_state.messages = []
|
| 23 |
|
|
|
|
| 24 |
for message in st.session_state.messages:
|
| 25 |
if isinstance(message, HumanMessage):
|
| 26 |
st.markdown(f"๐งโ๐ผ **You**: {message.content}")
|
| 27 |
elif isinstance(message, AIMessage):
|
| 28 |
st.markdown(f"๐ค **Assistant**: {message.content}")
|
| 29 |
|
| 30 |
+
if prompt := st.chat_input("Ask about the RFPs...", disabled=not st.session_state.get('vector_store')):
|
|
|
|
| 31 |
try:
|
| 32 |
with st.spinner("Analyzing documents..."):
|
|
|
|
| 33 |
human_message = HumanMessage(content=prompt)
|
|
|
|
|
|
|
| 34 |
st.session_state.messages.append(human_message)
|
| 35 |
|
|
|
|
| 36 |
response = st.session_state.qa_system.invoke({
|
| 37 |
"input": prompt,
|
| 38 |
+
"chat_history": list(st.session_state.messages)
|
| 39 |
})
|
| 40 |
|
| 41 |
if response:
|
|
|
|
| 44 |
st.rerun()
|
| 45 |
else:
|
| 46 |
st.error("No valid response received")
|
|
|
|
| 47 |
except Exception as e:
|
| 48 |
st.error(f"Error: {e}")
|
|
|
|
| 49 |
import traceback
|
| 50 |
+
st.error(traceback.format_exc())
|
| 51 |
+
|