8
8
print ('Done' .center (64 , '-' ))
9
9
10
10
# 加载模型
11
- model_name = 'THUDM/chatglm2 -6b'
11
+ model_name = 'THUDM/chatglm3 -6b'
12
12
13
- if 'chatglm2' in model_name .lower ():
13
+ if 'chatglm3' in model_name .lower ():
14
+ from predictors .chatglm3_predictor import ChatGLM3
15
+ predictor = ChatGLM3 (model_name )
16
+ elif 'chatglm2' in model_name .lower ():
14
17
from predictors .chatglm2_predictor import ChatGLM2
15
18
predictor = ChatGLM2 (model_name )
16
19
elif 'chatglm' in model_name .lower ():
31
34
32
35
33
36
def revise (history , latest_message ):
34
- history [- 1 ] = (history [- 1 ][0 ], latest_message )
37
+ if isinstance (history [- 1 ], tuple ):
38
+ history [- 1 ] = (history [- 1 ][0 ], latest_message )
39
+ elif isinstance (history [- 1 ], dict ):
40
+ history [- 1 ]['content' ] = latest_message
35
41
return history , ''
36
42
37
43
@@ -76,21 +82,21 @@ def regenerate(last_state, max_length, top_p, temperature, allow_generate):
76
82
""" )
77
83
with gr .Row ():
78
84
with gr .Column (scale = 4 ):
79
- chatbot = gr .Chatbot (elem_id = "chat-box" , show_label = False ). style ( height = 850 )
85
+ chatbot = gr .Chatbot (elem_id = "chat-box" , show_label = False , height = 850 )
80
86
with gr .Column (scale = 1 ):
81
87
with gr .Row ():
82
88
max_length = gr .Slider (32 , 4096 , value = 2048 , step = 1.0 , label = "Maximum length" , interactive = True )
83
89
top_p = gr .Slider (0.01 , 1 , value = 0.7 , step = 0.01 , label = "Top P" , interactive = True )
84
90
temperature = gr .Slider (0.01 , 5 , value = 0.95 , step = 0.01 , label = "Temperature" , interactive = True )
85
91
with gr .Row ():
86
- query = gr .Textbox (show_label = False , placeholder = "Prompts" , lines = 4 ). style ( container = False )
92
+ query = gr .Textbox (show_label = False , placeholder = "Prompts" , lines = 4 )
87
93
generate_button = gr .Button ("生成" )
88
94
with gr .Row ():
89
95
continue_message = gr .Textbox (
90
- show_label = False , placeholder = "Continue message" , lines = 2 ). style ( container = False )
96
+ show_label = False , placeholder = "Continue message" , lines = 2 )
91
97
continue_btn = gr .Button ("续写" )
92
98
revise_message = gr .Textbox (
93
- show_label = False , placeholder = "Revise message" , lines = 2 ). style ( container = False )
99
+ show_label = False , placeholder = "Revise message" , lines = 2 )
94
100
revise_btn = gr .Button ("修订" )
95
101
revoke_btn = gr .Button ("撤回" )
96
102
regenerate_btn = gr .Button ("重新生成" )
@@ -114,5 +120,5 @@ def regenerate(last_state, max_length, top_p, temperature, allow_generate):
114
120
outputs = [chatbot , query , continue_message ])
115
121
interrupt_btn .click (interrupt , inputs = [allow_generate ])
116
122
117
- demo .queue (concurrency_count = 4 ).launch (server_name = '0.0.0.0' , server_port = 7860 , share = False , inbrowser = False )
123
+ demo .queue ().launch (server_name = '0.0.0.0' , server_port = 7860 , share = False , inbrowser = False )
118
124
demo .close ()
0 commit comments