Spaces:
Build error
Build error
Update components/chat.py
Browse files4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152534 unmodified linesdef display_chat_interface():# Check if vector store exists and is properly loadedif 'vector_store' not in st.session_state:st.warning("π Please upload documents first.")return# Verify vector store has documentsif not verify_vector_store(st.session_state.vector_store):st.warning("β Documents are still being processed. Please wait...")return"""Display chat interface component"""st.markdown("### π¬ RFP Analysis Chat")if 'messages' not in st.session_state:st.session_state.messages = []for message in st.session_state.messages:if isinstance(message, HumanMessage):st.markdown(f"π§βπΌ **You**: {message.content}")elif isinstance(message, AIMessage):st.markdown(f"π€ **Assistant**: {message.content}")if prompt := st.chat_input("Ask about the RFPs...", disabled=not st.session_state.get('vector_store')):try:with st.spinner("Analyzing documents..."):human_message = HumanMessage(content=prompt)st.session_state.messages.append(human_message)response = st.session_state.qa_system.invoke({"input": prompt,"chat_history": list(st.session_state.messages)})if response:ai_message = AIMessage(content=str(response))st.session_state.messages.append(ai_message)st.rerun()else:st.error("No valid response received")except Exception as e:st.error(f"Error: {e}")import tracebackst.error(traceback.format_exc())4 unmodified lines56789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354554 unmodified linesdef display_chat_interface():"""Display chat interface component"""st.markdown("### π¬ RFP Analysis Chat")# Initialize chat history if not existsif 'messages' not in st.session_state:st.session_state.messages = []# Display chat historyfor message in st.session_state.messages:if isinstance(message, HumanMessage):st.markdown(f"π§βπΌ **You**: {message.content}")elif isinstance(message, AIMessage):st.markdown(f"π€ **Assistant**: {message.content}")# Chat inputif prompt := st.chat_input("Ask about the RFPs..."):try:with st.spinner("Analyzing documents..."):# Create message objectshuman_message = HumanMessage(content=prompt)# Add to chat historyst.session_state.messages.append(human_message)# Get response from QA systemresponse = st.session_state.qa_system.invoke({"input": prompt,"chat_history": st.session_state.messages})if response:# Create AI messageai_message = AIMessage(content=str(response))# Add to chat historyst.session_state.messages.append(ai_message)# Force refresh to show new messagesst.rerun()else:st.error("No valid response received")except Exception as e:st.error(f"Error: {e}")st.error(f"Error type: {type(e)}")import tracebackst.error(traceback.format_exc())
components/chat.py+16-14