Implement fluent cli demo

This commit is contained in:
duzx16 2023-06-27 09:51:05 +08:00
parent 8a0f57b1da
commit 761db39c1b

View File

@ -39,7 +39,8 @@ def main():
os.system(clear_command) os.system(clear_command)
print("欢迎使用 ChatGLM2-6B 模型输入内容即可进行对话clear 清空对话历史stop 终止程序") print("欢迎使用 ChatGLM2-6B 模型输入内容即可进行对话clear 清空对话历史stop 终止程序")
continue continue
count = 0 print("\nChatGLM", end="")
current_length = 0
for response, history, past_key_values in model.stream_chat(tokenizer, query, history=history, for response, history, past_key_values in model.stream_chat(tokenizer, query, history=history,
past_key_values=past_key_values, past_key_values=past_key_values,
return_past_key_values=True): return_past_key_values=True):
@ -47,13 +48,9 @@ def main():
stop_stream = False stop_stream = False
break break
else: else:
count += 1 print(response[current_length:], end="", flush=True)
if count % 8 == 0: current_length = len(response)
os.system(clear_command) print("")
print(build_prompt(history), flush=True)
signal.signal(signal.SIGINT, signal_handler)
os.system(clear_command)
print(build_prompt(history), flush=True)
if __name__ == "__main__": if __name__ == "__main__":