Spaces:
Sleeping
Sleeping
Commit
·
c89ea47
1
Parent(s):
19d6ccf
feat: return document from conversation chain
Browse files
app.py
CHANGED
|
@@ -38,19 +38,23 @@ def initialize_session_state():
|
|
| 38 |
)
|
| 39 |
|
| 40 |
memory = ConversationBufferMemory(
|
| 41 |
-
memory_key="chat_history", return_messages=True
|
| 42 |
)
|
| 43 |
st.session_state.conversation = ConversationalRetrievalChain.from_llm(
|
| 44 |
-
llm=llm,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
|
| 48 |
def on_click_callback():
|
| 49 |
with get_openai_callback() as cb:
|
| 50 |
human_prompt = st.session_state.human_prompt
|
| 51 |
-
llm_response = st.session_state.conversation
|
| 52 |
st.session_state.history.append(Message("human", human_prompt))
|
| 53 |
-
st.session_state.history.append(Message("ai", llm_response))
|
| 54 |
st.session_state.token_count += cb.total_tokens
|
| 55 |
|
| 56 |
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
memory = ConversationBufferMemory(
|
| 41 |
+
output_key="answer", memory_key="chat_history", return_messages=True
|
| 42 |
)
|
| 43 |
st.session_state.conversation = ConversationalRetrievalChain.from_llm(
|
| 44 |
+
llm=llm,
|
| 45 |
+
retriever=retriever,
|
| 46 |
+
verbose=True,
|
| 47 |
+
memory=memory,
|
| 48 |
+
return_source_documents=True,
|
| 49 |
)
|
| 50 |
|
| 51 |
|
| 52 |
def on_click_callback():
|
| 53 |
with get_openai_callback() as cb:
|
| 54 |
human_prompt = st.session_state.human_prompt
|
| 55 |
+
llm_response = st.session_state.conversation(human_prompt)
|
| 56 |
st.session_state.history.append(Message("human", human_prompt))
|
| 57 |
+
st.session_state.history.append(Message("ai", llm_response["answer"]))
|
| 58 |
st.session_state.token_count += cb.total_tokens
|
| 59 |
|
| 60 |
|