Du Mingzhe
commited on
Commit
•
bbd69b8
1
Parent(s):
9f65536
Update
Browse files- app.py +2 -1
- components.py +3 -6
app.py
CHANGED
@@ -13,6 +13,7 @@ pinecone_client = PersonalIndexClient(index_token=st.secrets["PINECONE_API_KEY"]
|
|
13 |
if "messages" not in st.session_state:
|
14 |
st.session_state.messages = []
|
15 |
st.session_state['sid'] = uuid.uuid1().hex
|
|
|
16 |
|
17 |
# Display History
|
18 |
for message in st.session_state.messages:
|
@@ -30,4 +31,4 @@ if prompt := st.chat_input("What's up?"):
|
|
30 |
response = st.write_stream(stream)
|
31 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
32 |
|
33 |
-
pinecone_client.update_conversation(sid=st.session_state['sid'], messages=st.session_state.messages, namespace='
|
|
|
13 |
if "messages" not in st.session_state:
|
14 |
st.session_state.messages = []
|
15 |
st.session_state['sid'] = uuid.uuid1().hex
|
16 |
+
st.session_state['user'] = 'default'
|
17 |
|
18 |
# Display History
|
19 |
for message in st.session_state.messages:
|
|
|
31 |
response = st.write_stream(stream)
|
32 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
33 |
|
34 |
+
pinecone_client.update_conversation(sid=st.session_state['sid'], messages=st.session_state.messages, namespace=st.session_state['user'])
|
components.py
CHANGED
@@ -81,7 +81,7 @@ class PersonalIndexClient(object):
|
|
81 |
)
|
82 |
return results
|
83 |
|
84 |
-
def update_conversation(self, sid, messages,
|
85 |
index_id = f'conv_{sid}'
|
86 |
|
87 |
messages_dump = json.dumps(messages)
|
@@ -89,11 +89,8 @@ class PersonalIndexClient(object):
|
|
89 |
metadata = {
|
90 |
'time': datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
|
91 |
'type': 'conversation',
|
|
|
92 |
'content': messages_dump,
|
93 |
}
|
94 |
|
95 |
-
self.create(data=[{
|
96 |
-
'id': index_id,
|
97 |
-
'content': messages_dump,
|
98 |
-
'metadata': metadata,
|
99 |
-
}])
|
|
|
81 |
)
|
82 |
return results
|
83 |
|
84 |
+
def update_conversation(self, sid, messages, user):
|
85 |
index_id = f'conv_{sid}'
|
86 |
|
87 |
messages_dump = json.dumps(messages)
|
|
|
89 |
metadata = {
|
90 |
'time': datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
|
91 |
'type': 'conversation',
|
92 |
+
'user': user,
|
93 |
'content': messages_dump,
|
94 |
}
|
95 |
|
96 |
+
self.create(data=[{'id': index_id, 'content': messages_dump, 'metadata': metadata,}], namespace=user)
|
|
|
|
|
|
|
|