MZhaovo commited on
Commit
8b274fe
·
1 Parent(s): 6ef2d2c

feat: Add switch for Remain System Prompt.(#907)

Browse files
ChuanhuChatbot.py CHANGED
@@ -203,6 +203,8 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
203
  value=INITIAL_SYSTEM_PROMPT,
204
  lines=8
205
  )
 
 
206
  with gr.Accordion(label=i18n("加载Prompt模板"), open=False):
207
  with gr.Column():
208
  with gr.Row():
@@ -582,10 +584,10 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
582
 
583
  emptyBtn.click(
584
  reset,
585
- inputs=[current_model],
586
  outputs=[chatbot, status_display, historySelectList, systemPromptTxt],
587
  show_progress=True,
588
- _js='clearChatbot',
589
  )
590
 
591
  retryBtn.click(**start_outputing_args).then(
@@ -680,10 +682,10 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
680
  historyRefreshBtn.click(**refresh_history_args)
681
  historyDeleteBtn.click(delete_chat_history, [current_model, historySelectList, user_name], [status_display, historySelectList, chatbot], _js='(a,b,c)=>{return showConfirmationDialog(a, b, c);}').then(
682
  reset,
683
- inputs=[current_model],
684
- outputs=[chatbot, status_display, historySelectList],
685
  show_progress=True,
686
- _js='clearChatbot',
687
  )
688
  historySelectList.input(**load_history_from_file_args)
689
  uploadFileBtn.upload(upload_chat_history, [current_model, uploadFileBtn, user_name], [
 
203
  value=INITIAL_SYSTEM_PROMPT,
204
  lines=8
205
  )
206
+ remain_system_prompt_checkbox = gr.Checkbox(
207
+ label=i18n("新建对话保留Prompt"), value=False, visible=True, elem_classes="switch-checkbox")
208
  with gr.Accordion(label=i18n("加载Prompt模板"), open=False):
209
  with gr.Column():
210
  with gr.Row():
 
584
 
585
  emptyBtn.click(
586
  reset,
587
+ inputs=[current_model, remain_system_prompt_checkbox],
588
  outputs=[chatbot, status_display, historySelectList, systemPromptTxt],
589
  show_progress=True,
590
+ _js='(a,b)=>{return clearChatbot(a,b);}',
591
  )
592
 
593
  retryBtn.click(**start_outputing_args).then(
 
682
  historyRefreshBtn.click(**refresh_history_args)
683
  historyDeleteBtn.click(delete_chat_history, [current_model, historySelectList, user_name], [status_display, historySelectList, chatbot], _js='(a,b,c)=>{return showConfirmationDialog(a, b, c);}').then(
684
  reset,
685
+ inputs=[current_model, remain_system_prompt_checkbox],
686
+ outputs=[chatbot, status_display, historySelectList, systemPromptTxt],
687
  show_progress=True,
688
+ _js='(a,b)=>{return clearChatbot(a,b);}',
689
  )
690
  historySelectList.input(**load_history_from_file_args)
691
  uploadFileBtn.upload(upload_chat_history, [current_model, uploadFileBtn, user_name], [
modules/models/XMChat.py CHANGED
@@ -28,7 +28,7 @@ class XMChat(BaseLLMModel):
28
  self.url = "https://xmbot.net/web"
29
  self.last_conv_id = None
30
 
31
- def reset(self):
32
  self.session_id = str(uuid.uuid4())
33
  self.last_conv_id = None
34
  return super().reset()
@@ -146,4 +146,4 @@ class XMChat(BaseLLMModel):
146
  response = json.loads(response.text)
147
  return response["data"], len(response["data"])
148
  except Exception as e:
149
- return response.text, len(response.text)
 
28
  self.url = "https://xmbot.net/web"
29
  self.last_conv_id = None
30
 
31
+ def reset(self, remain_system_prompt=False):
32
  self.session_id = str(uuid.uuid4())
33
  self.last_conv_id = None
34
  return super().reset()
 
146
  response = json.loads(response.text)
147
  return response["data"], len(response["data"])
148
  except Exception as e:
149
+ return response.text, len(response.text)
modules/models/base_model.py CHANGED
@@ -627,14 +627,15 @@ class BaseLLMModel:
627
  def set_single_turn(self, new_single_turn):
628
  self.single_turn = new_single_turn
629
 
630
- def reset(self):
631
  self.history = []
632
  self.all_token_counts = []
633
  self.interrupted = False
634
  self.history_file_path = new_auto_history_filename(self.user_identifier)
635
  history_name = self.history_file_path[:-5]
636
  choices = [history_name] + get_history_names(self.user_identifier)
637
- return [], self.token_message([0]), gr.Radio.update(choices=choices, value=history_name), ""
 
638
 
639
  def delete_first_conversation(self):
640
  if self.history:
 
627
  def set_single_turn(self, new_single_turn):
628
  self.single_turn = new_single_turn
629
 
630
+ def reset(self, remain_system_prompt=False):
631
  self.history = []
632
  self.all_token_counts = []
633
  self.interrupted = False
634
  self.history_file_path = new_auto_history_filename(self.user_identifier)
635
  history_name = self.history_file_path[:-5]
636
  choices = [history_name] + get_history_names(self.user_identifier)
637
+ system_prompt = self.system_prompt if remain_system_prompt else ""
638
+ return [], self.token_message([0]), gr.Radio.update(choices=choices, value=history_name), system_prompt
639
 
640
  def delete_first_conversation(self):
641
  if self.history:
modules/models/midjourney.py CHANGED
@@ -217,7 +217,7 @@ class Midjourney_Client(XMChat):
217
  logging.info("使用图片作为输入")
218
  return None, chatbot, None
219
 
220
- def reset(self):
221
  self.image_bytes = None
222
  self.image_path = None
223
  return super().reset()
 
217
  logging.info("使用图片作为输入")
218
  return None, chatbot, None
219
 
220
+ def reset(self, remain_system_prompt=False):
221
  self.image_bytes = None
222
  self.image_path = None
223
  return super().reset()
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -335,9 +335,10 @@ function setChatbotScroll() {
335
  chatbotWrap.scrollTo(0,scrollHeight)
336
  }
337
 
338
- function clearChatbot() {
339
  clearHistoryHtml();
340
  // clearMessageRows();
 
341
  }
342
 
343
  function chatbotContentChanged(attempt = 1, force = false) {
 
335
  chatbotWrap.scrollTo(0,scrollHeight)
336
  }
337
 
338
+ function clearChatbot(a, b) {
339
  clearHistoryHtml();
340
  // clearMessageRows();
341
+ return [a, b]
342
  }
343
 
344
  function chatbotContentChanged(attempt = 1, force = false) {