Skip to content

Commit f232ff3

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

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

cli_demo.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def signal_handler(signal, frame):
2929
def main():
3030
history = []
3131
global stop_stream
32+
signal.signal(signal.SIGINT, signal_handler)
3233
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
3334
while True:
3435
query = input("\n用户:")
@@ -39,20 +40,16 @@ def main():
3940
os.system(clear_command)
4041
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
4142
continue
42-
count = 0
43+
prev_response = ""
44+
print("ChatGLM-6B:", end="", flush=True)
4345
for response, history in model.stream_chat(tokenizer, query, history=history):
4446
if stop_stream:
4547
stop_stream = False
4648
break
4749
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-
50+
print(response[len(prev_response):], end="", flush=True)
51+
prev_response = response
52+
print("\n", end="", flush=True)
5653

5754
if __name__ == "__main__":
5855
main()

0 commit comments

Comments
 (0)