cryogenic22 commited on
Commit
f202cee
·
verified ·
1 Parent(s): a35c160

Update components/chat.py

Browse files
Files changed (1) hide show
  1. components/chat.py +3 -12
components/chat.py CHANGED
@@ -271,6 +271,7 @@ def display_chat_interface():
271
  </div>
272
  """, unsafe_allow_html=True)
273
 
 
274
  # Chat input
275
  if prompt := st.chat_input("Ask about your documents..."):
276
  with st.spinner("Analyzing..."):
@@ -284,22 +285,12 @@ def display_chat_interface():
284
  human_message = HumanMessage(content=prompt)
285
  st.session_state.messages.append(human_message)
286
 
287
- # Format chat history properly
288
- chat_history = []
289
- for msg in st.session_state.messages[:-1]: # Exclude the current message
290
- if isinstance(msg, (HumanMessage, AIMessage)):
291
- chat_history.append({
292
- "role": "user" if isinstance(msg, HumanMessage) else "assistant",
293
- "content": msg.content
294
- })
295
-
296
  # Get response from QA system
297
  response = st.session_state.qa_system.invoke({
298
  "input": prompt,
299
- "chat_history": [] # Start with empty history if causing issues
300
  })
301
 
302
- # Handle response
303
  if response:
304
  ai_message = AIMessage(content=str(response))
305
  st.session_state.messages.append(ai_message)
@@ -318,7 +309,7 @@ def display_chat_interface():
318
  st.rerun()
319
  else:
320
  st.error("No valid response received. Please try again.")
321
-
322
  except Exception as e:
323
  st.error(f"Error processing response: {str(e)}")
324
  st.error(traceback.format_exc())
 
271
  </div>
272
  """, unsafe_allow_html=True)
273
 
274
+ # Chat input
275
  # Chat input
276
  if prompt := st.chat_input("Ask about your documents..."):
277
  with st.spinner("Analyzing..."):
 
285
  human_message = HumanMessage(content=prompt)
286
  st.session_state.messages.append(human_message)
287
 
 
 
 
 
 
 
 
 
 
288
  # Get response from QA system
289
  response = st.session_state.qa_system.invoke({
290
  "input": prompt,
291
+ "chat_history": []
292
  })
293
 
 
294
  if response:
295
  ai_message = AIMessage(content=str(response))
296
  st.session_state.messages.append(ai_message)
 
309
  st.rerun()
310
  else:
311
  st.error("No valid response received. Please try again.")
312
+
313
  except Exception as e:
314
  st.error(f"Error processing response: {str(e)}")
315
  st.error(traceback.format_exc())