xu song
commited on
Commit
·
b57ad3d
1
Parent(s):
8607d84
update
Browse files- app_util.py +5 -5
app_util.py
CHANGED
@@ -22,13 +22,13 @@ from models.cpp_qwen2 import bot
|
|
22 |
def generate_user_message(chatbot, history):
|
23 |
if history and history[-1]["role"] == "user":
|
24 |
gr.Warning('You should generate assistant-response.')
|
25 |
-
yield
|
26 |
else:
|
27 |
chatbot.append(None)
|
28 |
streamer = bot.generate(history, stream=True)
|
29 |
for user_content, user_tokens in streamer:
|
30 |
chatbot[-1] = (user_content, None)
|
31 |
-
yield
|
32 |
user_tokens = bot.strip_stoptokens(user_tokens)
|
33 |
history.append({"role": "user", "content": user_content, "tokens": user_tokens})
|
34 |
yield chatbot, history
|
@@ -43,12 +43,12 @@ def generate_assistant_message(chatbot, history):
|
|
43 |
user_content = history[-1]["content"]
|
44 |
if history[-1]["role"] != "user":
|
45 |
gr.Warning('You should generate or type user-input first.')
|
46 |
-
yield
|
47 |
else:
|
48 |
streamer = bot.generate(history, stream=True)
|
49 |
for assistant_content, assistant_tokens in streamer:
|
50 |
chatbot[-1] = (user_content, assistant_content)
|
51 |
-
yield
|
52 |
|
53 |
assistant_tokens = bot.strip_stoptokens(assistant_tokens)
|
54 |
history.append({"role": "assistant", "content": assistant_content, "tokens": assistant_tokens})
|
@@ -101,7 +101,7 @@ def undo_generate(chatbot, history):
|
|
101 |
else:
|
102 |
pass
|
103 |
logger.info(f"after undo, {json.dumps(chatbot, ensure_ascii=False)}, {json.dumps(history, ensure_ascii=False)}")
|
104 |
-
return
|
105 |
|
106 |
|
107 |
def reset_user_input():
|
|
|
22 |
def generate_user_message(chatbot, history):
|
23 |
if history and history[-1]["role"] == "user":
|
24 |
gr.Warning('You should generate assistant-response.')
|
25 |
+
yield chatbot, history
|
26 |
else:
|
27 |
chatbot.append(None)
|
28 |
streamer = bot.generate(history, stream=True)
|
29 |
for user_content, user_tokens in streamer:
|
30 |
chatbot[-1] = (user_content, None)
|
31 |
+
yield chatbot, history
|
32 |
user_tokens = bot.strip_stoptokens(user_tokens)
|
33 |
history.append({"role": "user", "content": user_content, "tokens": user_tokens})
|
34 |
yield chatbot, history
|
|
|
43 |
user_content = history[-1]["content"]
|
44 |
if history[-1]["role"] != "user":
|
45 |
gr.Warning('You should generate or type user-input first.')
|
46 |
+
yield chatbot, history
|
47 |
else:
|
48 |
streamer = bot.generate(history, stream=True)
|
49 |
for assistant_content, assistant_tokens in streamer:
|
50 |
chatbot[-1] = (user_content, assistant_content)
|
51 |
+
yield chatbot, history
|
52 |
|
53 |
assistant_tokens = bot.strip_stoptokens(assistant_tokens)
|
54 |
history.append({"role": "assistant", "content": assistant_content, "tokens": assistant_tokens})
|
|
|
101 |
else:
|
102 |
pass
|
103 |
logger.info(f"after undo, {json.dumps(chatbot, ensure_ascii=False)}, {json.dumps(history, ensure_ascii=False)}")
|
104 |
+
return chatbot, history
|
105 |
|
106 |
|
107 |
def reset_user_input():
|