Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,13 +62,13 @@ def get_conversation_chain(vectorstore, model_name):
|
|
62 |
|
63 |
llm = ChatOpenAI()
|
64 |
|
65 |
-
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
66 |
|
67 |
conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm,
|
68 |
# condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
69 |
retriever=vectorstore.as_retriever(),
|
70 |
memory=memory,
|
71 |
-
|
72 |
)
|
73 |
|
74 |
return conversation_chain
|
@@ -79,15 +79,17 @@ def handle_userinput(user_question):
|
|
79 |
|
80 |
st.session_state.chat_history = response['chat_history']
|
81 |
|
82 |
-
|
83 |
|
84 |
-
for i, message in enumerate(st.session_state.chat_history):
|
85 |
if i % 2 == 0:
|
86 |
st.write(user_template.replace(
|
87 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
88 |
else:
|
89 |
st.write(bot_template.replace(
|
90 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
|
|
|
|
91 |
|
92 |
|
93 |
|
|
|
62 |
|
63 |
llm = ChatOpenAI()
|
64 |
|
65 |
+
memory = ConversationBufferMemory(memory_key='chat_history', input_key='question', output_key='answer', return_messages=True)
|
66 |
|
67 |
conversation_chain = ConversationalRetrievalChain.from_llm(llm=llm,
|
68 |
# condense_question_prompt=CONDENSE_QUESTION_PROMPT,
|
69 |
retriever=vectorstore.as_retriever(),
|
70 |
memory=memory,
|
71 |
+
return_source_documents=True
|
72 |
)
|
73 |
|
74 |
return conversation_chain
|
|
|
79 |
|
80 |
st.session_state.chat_history = response['chat_history']
|
81 |
|
82 |
+
st.session_state.retrieved_text = response['source_documents'][0]
|
83 |
|
84 |
+
for i, (message, text) in enumerate(zip(st.session_state.chat_history, st.session_state.retrieved_text):
|
85 |
if i % 2 == 0:
|
86 |
st.write(user_template.replace(
|
87 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
88 |
else:
|
89 |
st.write(bot_template.replace(
|
90 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
91 |
+
st.write(bot_template.replace(
|
92 |
+
"{{MSG}}", text.content), unsafe_allow_html=True)
|
93 |
|
94 |
|
95 |
|