File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ def signal_handler(signal, frame):
2929def 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
5754if __name__ == "__main__" :
5855 main ()
You can’t perform that action at this time.
0 commit comments