YC-Chen commited on
Commit
242bf8b
1 Parent(s): e35e05b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -142,7 +142,7 @@ with gr.Blocks() as demo:
142
 
143
 
144
  def user(user_message, history):
145
- return "", history + [[user_message, None]]
146
 
147
 
148
  def bot(history, max_new_tokens, temperature, top_p, system_prompt):
@@ -159,8 +159,10 @@ with gr.Blocks() as demo:
159
  message = tokenizer.apply_chat_template(chat_data, tokenize=False)
160
  message = message[3:] # remove SOT token
161
 
 
162
  if refusal_condition(history[-1][0]):
163
  history = [['[安全拒答啟動]', '[安全拒答啟動] 請清除再開啟對話']]
 
164
  yield history
165
  else:
166
  data = {
@@ -198,12 +200,10 @@ with gr.Blocks() as demo:
198
  except Exception as e:
199
  raise e
200
 
201
- if history[-1][1] is None:
202
- history[-1][1] = delta
203
- else:
204
- history[-1][1] += delta
205
  yield history
206
-
 
207
  if history[-1][1].endswith('</s>'):
208
  history[-1][1] = history[-1][1][:-4]
209
  yield history
@@ -213,8 +213,8 @@ with gr.Blocks() as demo:
213
  yield history
214
 
215
  print('== Record ==\nQuery: {query}\nResponse: {response}'.format(query=repr(message), response=repr(history[-1][1])))
216
- insert_to_db(message, history[-1][1], float(temperature), float(top_p))
217
-
218
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
219
  fn=bot,
220
  inputs=[
 
142
 
143
 
144
  def user(user_message, history):
145
+ return "", history + [[user_message, '']]
146
 
147
 
148
  def bot(history, max_new_tokens, temperature, top_p, system_prompt):
 
159
  message = tokenizer.apply_chat_template(chat_data, tokenize=False)
160
  message = message[3:] # remove SOT token
161
 
162
+ response = None
163
  if refusal_condition(history[-1][0]):
164
  history = [['[安全拒答啟動]', '[安全拒答啟動] 請清除再開啟對話']]
165
+ response = '[REFUSAL]'
166
  yield history
167
  else:
168
  data = {
 
200
  except Exception as e:
201
  raise e
202
 
203
+ history[-1][1] += delta
 
 
 
204
  yield history
205
+
206
+ response = history[-1][1]
207
  if history[-1][1].endswith('</s>'):
208
  history[-1][1] = history[-1][1][:-4]
209
  yield history
 
213
  yield history
214
 
215
  print('== Record ==\nQuery: {query}\nResponse: {response}'.format(query=repr(message), response=repr(history[-1][1])))
216
+ insert_to_db(message, response, float(temperature), float(top_p))
217
+
218
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
219
  fn=bot,
220
  inputs=[