Update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,7 @@ Recommendation:
|
|
52 |
|
53 |
PROMPT = PromptTemplate(
|
54 |
template=prompt_template,
|
55 |
-
input_variables=["chat_history", "question"]
|
56 |
)
|
57 |
|
58 |
# Initialize the language model
|
@@ -118,20 +118,14 @@ if prompt := st.chat_input("What are you looking to learn?"):
|
|
118 |
with st.chat_message("user"):
|
119 |
st.markdown(prompt)
|
120 |
|
121 |
-
# Retrieve relevant context from the vector store based on user input
|
122 |
-
context_documents = retriever.retrieve(prompt)
|
123 |
-
context = " ".join([doc.page_content for doc in context_documents]) # Combine the content of the retrieved documents
|
124 |
-
|
125 |
# Assistant response generator with streaming effect
|
126 |
with st.chat_message("assistant"):
|
127 |
-
response = qa_chain({"question": prompt
|
128 |
response_text = response["answer"]
|
129 |
-
|
130 |
# Simulate streaming response
|
131 |
-
full_response = ""
|
132 |
for word in response_text.split():
|
133 |
-
|
134 |
-
st.markdown(full_response.strip(), unsafe_allow_html=True) # Display the accumulated response
|
135 |
time.sleep(0.05) # Delay for effect
|
136 |
|
137 |
# Add assistant response to chat history
|
@@ -140,4 +134,4 @@ if prompt := st.chat_input("What are you looking to learn?"):
|
|
140 |
# Optional: Add a button to clear the chat history
|
141 |
if st.button("Clear Chat History"):
|
142 |
st.session_state.messages.clear()
|
143 |
-
st.experimental_rerun()
|
|
|
52 |
|
53 |
PROMPT = PromptTemplate(
|
54 |
template=prompt_template,
|
55 |
+
input_variables=["chat_history", "question", "context"]
|
56 |
)
|
57 |
|
58 |
# Initialize the language model
|
|
|
118 |
with st.chat_message("user"):
|
119 |
st.markdown(prompt)
|
120 |
|
|
|
|
|
|
|
|
|
121 |
# Assistant response generator with streaming effect
|
122 |
with st.chat_message("assistant"):
|
123 |
+
response = qa_chain({"question": prompt})
|
124 |
response_text = response["answer"]
|
125 |
+
|
126 |
# Simulate streaming response
|
|
|
127 |
for word in response_text.split():
|
128 |
+
st.markdown(word + " ", unsafe_allow_html=True)
|
|
|
129 |
time.sleep(0.05) # Delay for effect
|
130 |
|
131 |
# Add assistant response to chat history
|
|
|
134 |
# Optional: Add a button to clear the chat history
|
135 |
if st.button("Clear Chat History"):
|
136 |
st.session_state.messages.clear()
|
137 |
+
st.experimental_rerun()
|