cryogenic22 commited on
Commit
96b4624
ยท
verified ยท
1 Parent(s): 914b163

Update components/chat.py

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