ArturG9 commited on
Commit
237d231
·
verified ·
1 Parent(s): 0713e0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -149,8 +149,9 @@ def display_documents(docs, on_click=None):
149
 
150
  def main(conversational_rag_chain):
151
  """Main function for the Streamlit app."""
152
- msgs = st.session_state.get("chat_history", StreamlitChatMessageHistory()) # Initialize chat history
153
- chain_with_history =conversational_rag_chain
 
154
 
155
  st.title("Conversational RAG Chatbot")
156
 
@@ -160,10 +161,13 @@ def main(conversational_rag_chain):
160
  if prompt := st.chat_input():
161
  st.chat_message("human").write(prompt)
162
 
163
- # Process user input
 
164
  config = {"configurable": {"session_id": "any"}}
165
- response = chain_with_history.invoke({"question": prompt}, config)
166
- st.chat_message("ai").write(response.content)
 
 
167
 
168
  # Display retrieved documents (if any and present in response)
169
  if "docs" in response and response["documents"]:
@@ -173,7 +177,8 @@ def main(conversational_rag_chain):
173
  st.write(f"Expanding document {index+1}...")
174
  display_documents(docs, expand_document) # Pass click function
175
 
176
- st.session_state["chat_history"] = msgs # Update chat history in session state
 
177
 
178
  if __name__ == "__main__":
179
  main(conversational_rag_chain)
 
149
 
150
  def main(conversational_rag_chain):
151
  """Main function for the Streamlit app."""
152
+ # Initialize chat history if not already present in session state
153
+ msgs = st.session_state.get("chat_history", StreamlitChatMessageHistory(key="special_app_key"))
154
+ chain_with_history = conversational_rag_chain
155
 
156
  st.title("Conversational RAG Chatbot")
157
 
 
161
  if prompt := st.chat_input():
162
  st.chat_message("human").write(prompt)
163
 
164
+ # Prepare the input dictionary with the correct keys
165
+ input_dict = {"input": prompt, "chat_history": msgs.messages}
166
  config = {"configurable": {"session_id": "any"}}
167
+
168
+ # Process user input and handle response
169
+ response = chain_with_history.invoke(input_dict, config)
170
+ st.chat_message("ai").write(response["answer"])
171
 
172
  # Display retrieved documents (if any and present in response)
173
  if "docs" in response and response["documents"]:
 
177
  st.write(f"Expanding document {index+1}...")
178
  display_documents(docs, expand_document) # Pass click function
179
 
180
+ # Update chat history in session state
181
+ st.session_state["chat_history"] = msgs
182
 
183
  if __name__ == "__main__":
184
  main(conversational_rag_chain)