Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
CHANGED
@@ -74,6 +74,8 @@ with gr.Blocks(title=title) as demo:
|
|
74 |
neighborhoods = mb.search(history[-1][0])
|
75 |
messages += neighborhoods
|
76 |
messages.append({"role": "user", "content": history[-1][0]})
|
|
|
|
|
77 |
print('user:', {"role": "user", "content": history[-1][0]})
|
78 |
print('neighborhoods:', neighborhoods)
|
79 |
|
@@ -101,6 +103,7 @@ with gr.Blocks(title=title) as demo:
|
|
101 |
def reset_model():
|
102 |
global messages
|
103 |
messages = [{"role": "system", "content": prompt_default}]
|
|
|
104 |
print("已重置模型")
|
105 |
return [[None, "已重置模型"]]
|
106 |
|
@@ -109,7 +112,7 @@ with gr.Blocks(title=title) as demo:
|
|
109 |
user_content = text[0:text.find("|")]
|
110 |
assistant_content = text[text.find("|") + 1:]
|
111 |
mb.upsert([Dialogue(user_content, assistant_content)])
|
112 |
-
return [[None, f"
|
113 |
|
114 |
|
115 |
msg.submit(user, [prompt, msg, chatbot], [msg, chatbot], queue=False).then(
|
@@ -121,3 +124,4 @@ with gr.Blocks(title=title) as demo:
|
|
121 |
|
122 |
if __name__ == "__main__":
|
123 |
demo.launch(height=520, show_api=False, auth=("luoshaoye", "19970812"))
|
|
|
|
74 |
neighborhoods = mb.search(history[-1][0])
|
75 |
messages += neighborhoods
|
76 |
messages.append({"role": "user", "content": history[-1][0]})
|
77 |
+
|
78 |
+
print('messages:', messages)
|
79 |
print('user:', {"role": "user", "content": history[-1][0]})
|
80 |
print('neighborhoods:', neighborhoods)
|
81 |
|
|
|
103 |
def reset_model():
|
104 |
global messages
|
105 |
messages = [{"role": "system", "content": prompt_default}]
|
106 |
+
mb.reset()
|
107 |
print("已重置模型")
|
108 |
return [[None, "已重置模型"]]
|
109 |
|
|
|
112 |
user_content = text[0:text.find("|")]
|
113 |
assistant_content = text[text.find("|") + 1:]
|
114 |
mb.upsert([Dialogue(user_content, assistant_content)])
|
115 |
+
return [[None, f"已将对话样例存入记忆区块\n问: {user_content}\n答: {assistant_content}"]]
|
116 |
|
117 |
|
118 |
msg.submit(user, [prompt, msg, chatbot], [msg, chatbot], queue=False).then(
|
|
|
124 |
|
125 |
if __name__ == "__main__":
|
126 |
demo.launch(height=520, show_api=False, auth=("luoshaoye", "19970812"))
|
127 |
+
# demo.launch(height=520, show_api=False)
|
memory.py
CHANGED
@@ -3,8 +3,7 @@
|
|
3 |
# @Author : BarryWang
|
4 |
# @FileName: memory.py
|
5 |
# @Github : https://github.com/BarryWangQwQ
|
6 |
-
|
7 |
-
# import time
|
8 |
|
9 |
from txtai.embeddings import Embeddings
|
10 |
|
@@ -38,8 +37,8 @@ class MemoryBlocks:
|
|
38 |
def upsert(self, dialogue_list):
|
39 |
self.embeddings.upsert(
|
40 |
(
|
41 |
-
|
42 |
-
) for
|
43 |
)
|
44 |
|
45 |
def search(self, question: str) -> list:
|
@@ -51,12 +50,17 @@ class MemoryBlocks:
|
|
51 |
neighborhoods += eval(r['raw'])
|
52 |
return neighborhoods
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
# print(search("你是谁?"))
|
|
|
3 |
# @Author : BarryWang
|
4 |
# @FileName: memory.py
|
5 |
# @Github : https://github.com/BarryWangQwQ
|
6 |
+
import uuid
|
|
|
7 |
|
8 |
from txtai.embeddings import Embeddings
|
9 |
|
|
|
37 |
def upsert(self, dialogue_list):
|
38 |
self.embeddings.upsert(
|
39 |
(
|
40 |
+
str(uuid.uuid4()), {'text': dialogue.user_content, 'raw': dialogue.raw()}, None
|
41 |
+
) for dialogue in dialogue_list
|
42 |
)
|
43 |
|
44 |
def search(self, question: str) -> list:
|
|
|
50 |
neighborhoods += eval(r['raw'])
|
51 |
return neighborhoods
|
52 |
|
53 |
+
def reset(self):
|
54 |
+
self.embeddings.close()
|
55 |
+
self.embeddings = Embeddings(
|
56 |
+
{
|
57 |
+
"path": "sentence-transformers/distiluse-base-multilingual-cased-v2",
|
58 |
+
'content': True
|
59 |
+
}
|
60 |
+
)
|
61 |
+
|
62 |
+
def save(self, output_path):
|
63 |
+
self.embeddings.save(output_path)
|
64 |
|
65 |
+
def load(self, load_path):
|
66 |
+
self.embeddings.load(load_path)
|
|