Tuchuanhuhuhu commited on
Commit
786c822
1 Parent(s): a45e317

增加了删除早期历史记录的按钮

Browse files
Files changed (2) hide show
  1. ChuanhuChatbot.py +8 -1
  2. modules/utils.py +23 -2
ChuanhuChatbot.py CHANGED
@@ -88,7 +88,8 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
88
  "🧹 新的对话",
89
  )
90
  retryBtn = gr.Button("🔄 重新生成")
91
- delLastBtn = gr.Button("🗑️ 删除一条对话")
 
92
  reduceTokenBtn = gr.Button("♻️ 总结对话")
93
 
94
  with gr.Column():
@@ -301,6 +302,12 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
301
  ).then(**end_outputing_args)
302
  retryBtn.click(**get_usage_args)
303
 
 
 
 
 
 
 
304
  delLastBtn.click(
305
  delete_last_conversation,
306
  [chatbot, history, token_count],
 
88
  "🧹 新的对话",
89
  )
90
  retryBtn = gr.Button("🔄 重新生成")
91
+ delFirstBtn = gr.Button("🗑️ 删除早期历史")
92
+ delLastBtn = gr.Button("🗑️ 删除最后对话")
93
  reduceTokenBtn = gr.Button("♻️ 总结对话")
94
 
95
  with gr.Column():
 
302
  ).then(**end_outputing_args)
303
  retryBtn.click(**get_usage_args)
304
 
305
+ delFirstBtn.click(
306
+ delete_first_conversation,
307
+ [history, token_count],
308
+ [history, token_count, status_display],
309
+ )
310
+
311
  delLastBtn.click(
312
  delete_last_conversation,
313
  [chatbot, history, token_count],
modules/utils.py CHANGED
@@ -115,7 +115,11 @@ def convert_mdtext(md_text):
115
 
116
 
117
  def convert_asis(userinput):
118
- return f"<p style=\"white-space:pre-wrap;\">{html.escape(userinput)}</p>"+ALREADY_CONVERTED_MARK
 
 
 
 
119
 
120
  def detect_converted_mark(userinput):
121
  if userinput.endswith(ALREADY_CONVERTED_MARK):
@@ -154,6 +158,17 @@ def construct_token_message(token, stream=False):
154
  return f"Token 计数: {token}"
155
 
156
 
 
 
 
 
 
 
 
 
 
 
 
157
  def delete_last_conversation(chatbot, history, previous_token_count):
158
  if len(chatbot) > 0 and standard_error_msg in chatbot[-1][1]:
159
  logging.info("由于包含报错信息,只删除chatbot记录")
@@ -417,8 +432,14 @@ def cancel_outputing():
417
  logging.info("中止输出……")
418
  shared.state.interrupt()
419
 
 
420
  def transfer_input(inputs):
421
  # 一次性返回,降低延迟
422
  textbox = reset_textbox()
423
  outputing = start_outputing()
424
- return inputs, gr.update(value=""), gr.Button.update(visible=False), gr.Button.update(visible=True)
 
 
 
 
 
 
115
 
116
 
117
  def convert_asis(userinput):
118
+ return (
119
+ f'<p style="white-space:pre-wrap;">{html.escape(userinput)}</p>'
120
+ + ALREADY_CONVERTED_MARK
121
+ )
122
+
123
 
124
  def detect_converted_mark(userinput):
125
  if userinput.endswith(ALREADY_CONVERTED_MARK):
 
158
  return f"Token 计数: {token}"
159
 
160
 
161
+ def delete_first_conversation(history, previous_token_count):
162
+ if history:
163
+ del history[:2]
164
+ del previous_token_count[0]
165
+ return (
166
+ history,
167
+ previous_token_count,
168
+ construct_token_message(sum(previous_token_count)),
169
+ )
170
+
171
+
172
  def delete_last_conversation(chatbot, history, previous_token_count):
173
  if len(chatbot) > 0 and standard_error_msg in chatbot[-1][1]:
174
  logging.info("由于包含报错信息,只删除chatbot记录")
 
432
  logging.info("中止输出……")
433
  shared.state.interrupt()
434
 
435
+
436
  def transfer_input(inputs):
437
  # 一次性返回,降低延迟
438
  textbox = reset_textbox()
439
  outputing = start_outputing()
440
+ return (
441
+ inputs,
442
+ gr.update(value=""),
443
+ gr.Button.update(visible=False),
444
+ gr.Button.update(visible=True),
445
+ )