Spaces:
Build error
Build error
Update components/chat.py
Browse files1234567891011121314159 unmodified lines252627282930313233343536373839404142434445import streamlit as stfrom langchain.schema import HumanMessage, AIMessage, SystemMessagedef format_chat_history(chat_history):"""Format chat history for QA system"""formatted_history = []for msg in chat_history[:-1]: # Exclude the most recent messageif isinstance(msg, HumanMessage):formatted_history.append(SystemMessage(content=f"Human: {msg.content}"))elif isinstance(msg, AIMessage):formatted_history.append(SystemMessage(content=f"Assistant: {msg.content}"))return formatted_historydef display_chat_interface():"""Display chat interface component"""9 unmodified lines# Chat inputif prompt := st.chat_input("Ask about the RFPs..."):# Add user message to chat historyst.session_state.chat_history.append(HumanMessage(content=prompt))try:with st.spinner("Analyzing documents..."):# Create formatted history that Langchain expectsformatted_history = format_chat_history(st.session_state.chat_history)# Make the query with formatted historyresponse = st.session_state.qa_system.invoke({"input": prompt,"chat_history": formatted_history})# Add AI response to chat historyst.session_state.chat_history.append(AIMessage(content=response["output"]))except Exception as e:st.error(f"Error generating response: {e}")123459 unmodified lines15161718192021222324252627282930313233343536import streamlit as stfrom langchain.schema import HumanMessage, AIMessagedef display_chat_interface():"""Display chat interface component"""9 unmodified lines# Chat inputif prompt := st.chat_input("Ask about the RFPs..."):# Add user message to chat historycurrent_msg = HumanMessage(content=prompt)st.session_state.chat_history.append(current_msg)try:with st.spinner("Analyzing documents..."):# Pass only the messages list without formattingresponse = st.session_state.qa_system.invoke({"input": current_msg.content,"chat_history": st.session_state.chat_history[:-1] # Exclude current message})# Add AI response to chat historyst.session_state.chat_history.append(AIMessage(content=response["output"]))except Exception as e:st.error(f"Error generating response: {e}")# Print more detailed error informationimport tracebackst.error(f"Detailed error: {traceback.format_exc()}")
components/chat.py+10-19