Update app.py
Browse files
app.py
CHANGED
@@ -21,4 +21,22 @@ def load_data():
|
|
21 |
index = VectorStoreIndex.from_documents(docs, service_context=service_context)
|
22 |
return index
|
23 |
|
24 |
-
index = load_data()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
index = VectorStoreIndex.from_documents(docs, service_context=service_context)
|
22 |
return index
|
23 |
|
24 |
+
index = load_data()
|
25 |
+
|
26 |
+
chat_engine = index.as_chat_engine(chat_mode="condense_question", verbose=True)
|
27 |
+
|
28 |
+
if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
|
29 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
30 |
+
|
31 |
+
for message in st.session_state.messages: # Display the prior chat messages
|
32 |
+
with st.chat_message(message["role"]):
|
33 |
+
st.write(message["content"])
|
34 |
+
|
35 |
+
# If last message is not from assistant, generate a new response
|
36 |
+
if st.session_state.messages[-1]["role"] != "assistant":
|
37 |
+
with st.chat_message("assistant"):
|
38 |
+
with st.spinner("Thinking..."):
|
39 |
+
response = chat_engine.chat(prompt)
|
40 |
+
st.write(response.response)
|
41 |
+
message = {"role": "assistant", "content": response.response}
|
42 |
+
st.session_state.messages.append(message) # Add response to message history
|