Skip to content

Commit 95f4b23

Browse files
author
潕量
committed
fix: 优化控制台闪烁的问题
1 parent 163f94e commit 95f4b23

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

cli_demo.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,12 @@ def main():
3939
os.system(clear_command)
4040
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
4141
continue
42-
count = 0
42+
prev_response = ""
43+
print("ChatGLM-6B:", end="", flush=True)
4344
for response, history in model.stream_chat(tokenizer, query, history=history):
44-
if stop_stream:
45-
stop_stream = False
46-
break
47-
else:
48-
count += 1
49-
if count % 8 == 0:
50-
os.system(clear_command)
51-
print(build_prompt(history), flush=True)
52-
signal.signal(signal.SIGINT, signal_handler)
53-
os.system(clear_command)
54-
print(build_prompt(history), flush=True)
55-
45+
print(response[len(prev_response):], end="", flush=True)
46+
prev_response = response
47+
print("\n", end="", flush=True)
5648

5749
if __name__ == "__main__":
5850
main()

0 commit comments

Comments
 (0)