mirror of https://github.com/THUDM/ChatGLM-6B
feat: enhanced typewriter effect with emoji support
parent
963d5645ef
commit
0c87db07e8
30
cli_demo.py
30
cli_demo.py
|
@ -10,34 +10,34 @@ os_name = platform.system()
|
||||||
clear_command = 'cls' if os_name == 'Windows' else 'clear'
|
clear_command = 'cls' if os_name == 'Windows' else 'clear'
|
||||||
|
|
||||||
|
|
||||||
def build_prompt(history):
|
def build_prompt(history, prev_resp, count):
|
||||||
prompt = "欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序"
|
cur_resp = history[count][1][len(prev_resp[0]):]
|
||||||
for query, response in history:
|
d = cur_resp.encode('unicode_escape')
|
||||||
prompt += f"\n\n用户:{query}"
|
if b'\\ufff' in d:
|
||||||
prompt += f"\n\nChatGLM-6B:{response}"
|
return
|
||||||
return prompt
|
print(cur_resp, end='', flush=True)
|
||||||
|
prev_resp[0] += cur_resp
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
history = []
|
history = []
|
||||||
|
os.system(clear_command)
|
||||||
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
|
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
|
||||||
|
count = 0
|
||||||
while True:
|
while True:
|
||||||
query = input("\n用户:")
|
query = input("\n\n用户:")
|
||||||
if query == "stop":
|
if query == "stop":
|
||||||
break
|
break
|
||||||
if query == "clear":
|
if query == "clear":
|
||||||
history = []
|
history = []
|
||||||
|
count = 0
|
||||||
os.system(clear_command)
|
os.system(clear_command)
|
||||||
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
|
print("欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序")
|
||||||
continue
|
continue
|
||||||
count = 0
|
print('\nChat:', end='')
|
||||||
|
prev_resp = [""]
|
||||||
for response, history in model.stream_chat(tokenizer, query, history=history):
|
for response, history in model.stream_chat(tokenizer, query, history=history):
|
||||||
count += 1
|
build_prompt(history, prev_resp, count)
|
||||||
if count % 8 == 0:
|
count += 1
|
||||||
os.system(clear_command)
|
|
||||||
print(build_prompt(history), flush=True)
|
|
||||||
os.system(clear_command)
|
|
||||||
print(build_prompt(history), flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue