Tuchuanhuhuhu commited on
Commit
e898b8a
·
1 Parent(s): 531abe2

加入了单轮对话功能

Browse files
Files changed (3) hide show
  1. ChuanhuChatbot.py +7 -4
  2. modules/base_model.py +7 -0
  3. modules/models.py +3 -0
ChuanhuChatbot.py CHANGED
@@ -83,10 +83,12 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
83
  lora_select_dropdown = gr.Dropdown(
84
  label="选择LoRA模型", choices=[], multiselect=False, interactive=True, visible=False
85
  )
86
- use_streaming_checkbox = gr.Checkbox(
87
- label="实时传输回答", value=True, visible=ENABLE_STREAMING_OPTION
88
- )
89
- use_websearch_checkbox = gr.Checkbox(label="使用在线搜索", value=False)
 
 
90
  language_select_dropdown = gr.Dropdown(
91
  label="选择回复语言(针对搜索&索引功能)",
92
  choices=REPLY_LANGUAGES,
@@ -353,6 +355,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
353
  # LLM Models
354
  keyTxt.change(current_model.value.set_key, keyTxt, [status_display]).then(**get_usage_args)
355
  keyTxt.submit(**get_usage_args)
 
356
  model_select_dropdown.change(current_model.value.get_model, [model_select_dropdown, lora_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [status_display, lora_select_dropdown], show_progress=True)
357
  lora_select_dropdown.change(current_model.value.get_model, [model_select_dropdown, lora_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [status_display], show_progress=True)
358
 
 
83
  lora_select_dropdown = gr.Dropdown(
84
  label="选择LoRA模型", choices=[], multiselect=False, interactive=True, visible=False
85
  )
86
+ with gr.Row():
87
+ use_streaming_checkbox = gr.Checkbox(
88
+ label="实时传输回答", value=True, visible=ENABLE_STREAMING_OPTION
89
+ )
90
+ single_turn_checkbox = gr.Checkbox(label="单轮对话", value=False)
91
+ use_websearch_checkbox = gr.Checkbox(label="使用在线搜索", value=False)
92
  language_select_dropdown = gr.Dropdown(
93
  label="选择回复语言(针对搜索&索引功能)",
94
  choices=REPLY_LANGUAGES,
 
355
  # LLM Models
356
  keyTxt.change(current_model.value.set_key, keyTxt, [status_display]).then(**get_usage_args)
357
  keyTxt.submit(**get_usage_args)
358
+ single_turn_checkbox.change(current_model.value.set_single_turn, single_turn_checkbox, None)
359
  model_select_dropdown.change(current_model.value.get_model, [model_select_dropdown, lora_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [status_display, lora_select_dropdown], show_progress=True)
360
  lora_select_dropdown.change(current_model.value.get_model, [model_select_dropdown, lora_select_dropdown, keyTxt, temperature_slider, top_p_slider, systemPromptTxt], [status_display], show_progress=True)
361
 
modules/base_model.py CHANGED
@@ -71,6 +71,7 @@ class BaseLLMModel:
71
  self.system_prompt = system_prompt
72
  self.api_key = None
73
  self.need_api_key = False
 
74
 
75
  self.temperature = temperature
76
  self.top_p = top_p
@@ -285,6 +286,9 @@ class BaseLLMModel:
285
  yield chatbot + [(inputs, "")], status_text
286
  return
287
 
 
 
 
288
  self.history.append(construct_user(inputs))
289
 
290
  try:
@@ -439,6 +443,9 @@ class BaseLLMModel:
439
  logging.info(msg)
440
  return msg
441
 
 
 
 
442
  def reset(self):
443
  self.history = []
444
  self.all_token_counts = []
 
71
  self.system_prompt = system_prompt
72
  self.api_key = None
73
  self.need_api_key = False
74
+ self.single_turn = False
75
 
76
  self.temperature = temperature
77
  self.top_p = top_p
 
286
  yield chatbot + [(inputs, "")], status_text
287
  return
288
 
289
+ if self.single_turn:
290
+ self.history = []
291
+ self.all_token_counts = []
292
  self.history.append(construct_user(inputs))
293
 
294
  try:
 
443
  logging.info(msg)
444
  return msg
445
 
446
+ def set_single_turn(self, new_single_turn):
447
+ self.single_turn = new_single_turn
448
+
449
  def reset(self):
450
  self.history = []
451
  self.all_token_counts = []
modules/models.py CHANGED
@@ -526,6 +526,9 @@ class ModelManager:
526
  def set_user_identifier(self, *args):
527
  self.model.set_user_identifier(*args)
528
 
 
 
 
529
 
530
 
531
 
 
526
  def set_user_identifier(self, *args):
527
  self.model.set_user_identifier(*args)
528
 
529
+ def set_single_turn(self, *args):
530
+ self.model.set_single_turn(*args)
531
+
532
 
533
 
534