Du Mingzhe
commited on
Commit
•
9f65536
1
Parent(s):
143727a
update
Browse files- app.py +1 -9
- components.py +20 -1
app.py
CHANGED
@@ -30,12 +30,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 |
-
|
34 |
-
|
35 |
-
pinecone_client.create(data=[{
|
36 |
-
'id': '123',
|
37 |
-
'content': current_history,
|
38 |
-
'metadata': {'hello': 'world', 'content': current_history},
|
39 |
-
}])
|
40 |
-
|
41 |
-
|
|
|
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='default')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
components.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
# Author: Du Mingzhe ([email protected])
|
2 |
# Date: 2024/03/09
|
3 |
|
|
|
|
|
4 |
from openai import OpenAI
|
5 |
from pinecone import Pinecone
|
6 |
from datetime import datetime
|
@@ -77,4 +79,21 @@ class PersonalIndexClient(object):
|
|
77 |
include_metadata = True,
|
78 |
filter = filter,
|
79 |
)
|
80 |
-
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Author: Du Mingzhe ([email protected])
|
2 |
# Date: 2024/03/09
|
3 |
|
4 |
+
import json
|
5 |
+
|
6 |
from openai import OpenAI
|
7 |
from pinecone import Pinecone
|
8 |
from datetime import datetime
|
|
|
79 |
include_metadata = True,
|
80 |
filter = filter,
|
81 |
)
|
82 |
+
return results
|
83 |
+
|
84 |
+
def update_conversation(self, sid, messages, namespace='default'):
|
85 |
+
index_id = f'conv_{sid}'
|
86 |
+
|
87 |
+
messages_dump = json.dumps(messages)
|
88 |
+
|
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 |
+
}])
|