Spaces:
Sleeping
Sleeping
Merge branch 'fix_memory' into main
Browse files
app.py
CHANGED
|
@@ -37,21 +37,18 @@ def initialize_session_state():
|
|
| 37 |
model="text-davinci-003",
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
st.session_state.conversation = ConversationalRetrievalChain.from_llm(
|
| 42 |
-
llm=llm, retriever=retriever, verbose=True
|
| 43 |
)
|
| 44 |
|
| 45 |
|
| 46 |
def on_click_callback():
|
| 47 |
with get_openai_callback() as cb:
|
| 48 |
human_prompt = st.session_state.human_prompt
|
| 49 |
-
llm_response = st.session_state.conversation.run(
|
| 50 |
-
{
|
| 51 |
-
"question": human_prompt,
|
| 52 |
-
"chat_history": st.session_state.memory.buffer,
|
| 53 |
-
}
|
| 54 |
-
)
|
| 55 |
st.session_state.history.append(Message("human", human_prompt))
|
| 56 |
st.session_state.history.append(Message("ai", llm_response))
|
| 57 |
st.session_state.token_count += cb.total_tokens
|
|
@@ -105,7 +102,7 @@ information_placeholder.caption(
|
|
| 105 |
f"""
|
| 106 |
Used {st.session_state.token_count} tokens \n
|
| 107 |
Debug Langchain conversation:
|
| 108 |
-
{st.session_state.memory.buffer}
|
| 109 |
"""
|
| 110 |
)
|
| 111 |
|
|
|
|
| 37 |
model="text-davinci-003",
|
| 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, retriever=retriever, verbose=True, memory=memory
|
| 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.run(human_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 102 |
f"""
|
| 103 |
Used {st.session_state.token_count} tokens \n
|
| 104 |
Debug Langchain conversation:
|
| 105 |
+
{st.session_state.conversation.memory.buffer}
|
| 106 |
"""
|
| 107 |
)
|
| 108 |
|