Spaces:
Running
Running
jonathanjordan21
commited on
Commit
•
b492afd
1
Parent(s):
e19073c
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ from typing import Optional
|
|
11 |
|
12 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
13 |
from langchain_core.chat_history import BaseChatMessageHistory
|
14 |
-
from langchain.memory import ConversationBufferMemory
|
15 |
|
16 |
|
17 |
|
@@ -22,16 +22,16 @@ POSTGRE_URL = os.environ['POSTGRE_URL']
|
|
22 |
|
23 |
|
24 |
if 'memory' not in st.session_state:
|
25 |
-
|
26 |
|
27 |
-
st.session_state.memory = PostgresChatMessageHistory(connection_string=POSTGRE_URL, session_id=str(datetime.timestamp(datetime.now())))
|
28 |
-
st.session_state.memory.add_ai_message("Hello, My name is Jonathan Jordan. You can call me Jojo. How can I help you today?")
|
29 |
|
30 |
if 'chain' not in st.session_state:
|
31 |
st.session_state['chain'] = custom_chain_with_history(
|
32 |
llm=CustomLLM(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", model_type='text-generation', api_token=API_TOKEN, stop=["\n<|","<|"], temperature=0.001),
|
33 |
-
|
34 |
-
memory=st.session_state.memory
|
35 |
)
|
36 |
|
37 |
st.title("Chat With Me")
|
@@ -58,10 +58,10 @@ if prompt := st.chat_input("Ask me anything.."):
|
|
58 |
# Display assistant response in chat message container
|
59 |
with st.chat_message("assistant"):
|
60 |
st.markdown(response)
|
61 |
-
st.session_state.memory.add_user_message(prompt)
|
62 |
-
st.session_state.memory.add_ai_message(response)
|
63 |
-
|
64 |
-
|
65 |
# Add assistant response to chat history
|
66 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
67 |
|
|
|
11 |
|
12 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
13 |
from langchain_core.chat_history import BaseChatMessageHistory
|
14 |
+
from langchain.memory import ConversationBufferMemory#, PostgresChatMessageHistory
|
15 |
|
16 |
|
17 |
|
|
|
22 |
|
23 |
|
24 |
if 'memory' not in st.session_state:
|
25 |
+
st.session_state['memory'] = ConversationBufferMemory(return_messages=True)
|
26 |
|
27 |
+
# st.session_state.memory = PostgresChatMessageHistory(connection_string=POSTGRE_URL, session_id=str(datetime.timestamp(datetime.now())))
|
28 |
+
# st.session_state.memory.add_ai_message("Hello, My name is Jonathan Jordan. You can call me Jojo. How can I help you today?")
|
29 |
|
30 |
if 'chain' not in st.session_state:
|
31 |
st.session_state['chain'] = custom_chain_with_history(
|
32 |
llm=CustomLLM(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", model_type='text-generation', api_token=API_TOKEN, stop=["\n<|","<|"], temperature=0.001),
|
33 |
+
memory=st.session_state.memory.chat_memory,
|
34 |
+
# memory=st.session_state.memory
|
35 |
)
|
36 |
|
37 |
st.title("Chat With Me")
|
|
|
58 |
# Display assistant response in chat message container
|
59 |
with st.chat_message("assistant"):
|
60 |
st.markdown(response)
|
61 |
+
# st.session_state.memory.add_user_message(prompt)
|
62 |
+
# st.session_state.memory.add_ai_message(response)
|
63 |
+
st.session_state.memory.save_context({"question":prompt}, {"output":response})
|
64 |
+
st.session_state.memory.chat_memory.messages = st.session_state.memory.chat_memory.messages[-15:]
|
65 |
# Add assistant response to chat history
|
66 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
67 |
|