Spaces:
Runtime error
Runtime error
yuxj
commited on
Commit
•
0537da4
1
Parent(s):
d67a35e
清除聊天历史有问题
Browse files
app.py
CHANGED
@@ -4,11 +4,13 @@ import time
|
|
4 |
|
5 |
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
|
6 |
model = AutoModel.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True).float()
|
7 |
-
|
8 |
glm_history = []
|
9 |
-
|
10 |
-
|
11 |
-
glm_history
|
|
|
|
|
|
|
12 |
|
13 |
def chat_with_glm(input):
|
14 |
print("询问: ", input)
|
@@ -32,7 +34,7 @@ def on_submit(input, history):
|
|
32 |
history.append((input, respond + history_str))
|
33 |
elif input == '--clear':
|
34 |
history = []
|
35 |
-
|
36 |
else:
|
37 |
history.append((input, respond + chat_with_glm(input)))
|
38 |
return "", history
|
@@ -43,4 +45,5 @@ with gr.Blocks() as demo:
|
|
43 |
tv_input = gr.Textbox()
|
44 |
tv_input.submit(fn = on_submit, inputs = [tv_input, chatbot], outputs = [tv_input, chatbot])
|
45 |
gr.Markdown("<b>说明:</b><br/>输入\"--clear\"清空历史,输入\"--history\"查看历史")
|
|
|
46 |
demo.launch()
|
|
|
4 |
|
5 |
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True)
|
6 |
model = AutoModel.from_pretrained("THUDM/chatglm-6b-int4", trust_remote_code=True).float()
|
|
|
7 |
glm_history = []
|
8 |
+
|
9 |
+
def reset_glm():
|
10 |
+
global glm_history
|
11 |
+
settings = "请记住以下设定:你后续跟我的聊天过程中不可以出现“ChatGLM”这个单词,如果你被要求自我介绍,就说自己是基于AI的聊天模型"
|
12 |
+
response, history = model.chat(tokenizer, settings, history =[])
|
13 |
+
glm_history = history
|
14 |
|
15 |
def chat_with_glm(input):
|
16 |
print("询问: ", input)
|
|
|
34 |
history.append((input, respond + history_str))
|
35 |
elif input == '--clear':
|
36 |
history = []
|
37 |
+
reset_glm()
|
38 |
else:
|
39 |
history.append((input, respond + chat_with_glm(input)))
|
40 |
return "", history
|
|
|
45 |
tv_input = gr.Textbox()
|
46 |
tv_input.submit(fn = on_submit, inputs = [tv_input, chatbot], outputs = [tv_input, chatbot])
|
47 |
gr.Markdown("<b>说明:</b><br/>输入\"--clear\"清空历史,输入\"--history\"查看历史")
|
48 |
+
reset_glm()
|
49 |
demo.launch()
|