Tuchuanhuhuhu commited on
Commit
7dfecf7
·
1 Parent(s): c01b032

解决登录后上传对话历史记录无效的问题

Browse files
ChuanhuChatbot.py CHANGED
@@ -426,7 +426,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
426
  )
427
  historyRefreshBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
428
  historyFileSelectDropdown.change(**load_history_from_file_args)
429
- downloadFile.change(**load_history_from_file_args)
430
 
431
  # Advanced
432
  max_context_length_slider.change(set_token_upper_limit, [current_model, max_context_length_slider], None)
 
426
  )
427
  historyRefreshBtn.click(get_history_names, [gr.State(False), user_name], [historyFileSelectDropdown])
428
  historyFileSelectDropdown.change(**load_history_from_file_args)
429
+ downloadFile.change(upload_chat_history, [current_model, downloadFile, user_name], [saveFileName, systemPromptTxt, chatbot])
430
 
431
  # Advanced
432
  max_context_length_slider.change(set_token_upper_limit, [current_model, max_context_length_slider], None)
modules/models/base_model.py CHANGED
@@ -538,6 +538,7 @@ class BaseLLMModel:
538
 
539
  def load_chat_history(self, filename, user_name):
540
  logging.debug(f"{user_name} 加载对话历史中……")
 
541
  if type(filename) != str:
542
  filename = filename.name
543
  try:
@@ -562,11 +563,11 @@ class BaseLLMModel:
562
  pass
563
  logging.debug(f"{user_name} 加载对话历史完毕")
564
  self.history = json_s["history"]
565
- return filename, json_s["system"], json_s["chatbot"]
566
  except:
567
  # 没有对话历史或者对话历史解析失败
568
  logging.info(f"没有找到对话历史记录 {history_file_path}")
569
- return filename, self.system_prompt, gr.update()
570
 
571
  def auto_load(self):
572
  if self.user_identifier == "":
 
538
 
539
  def load_chat_history(self, filename, user_name):
540
  logging.debug(f"{user_name} 加载对话历史中……")
541
+ logging.info(f"filename: {filename}")
542
  if type(filename) != str:
543
  filename = filename.name
544
  try:
 
563
  pass
564
  logging.debug(f"{user_name} 加载对话历史完毕")
565
  self.history = json_s["history"]
566
+ return os.path.basename(filename), json_s["system"], json_s["chatbot"]
567
  except:
568
  # 没有对话历史或者对话历史解析失败
569
  logging.info(f"没有找到对话历史记录 {history_file_path}")
570
+ return os.path.basename(filename), self.system_prompt, gr.update()
571
 
572
  def auto_load(self):
573
  if self.user_identifier == "":
modules/utils.py CHANGED
@@ -77,6 +77,10 @@ def export_markdown(current_model, *args):
77
  def load_chat_history(current_model, *args):
78
  return current_model.load_chat_history(*args)
79
 
 
 
 
 
80
  def set_token_upper_limit(current_model, *args):
81
  return current_model.set_token_upper_limit(*args)
82
 
 
77
  def load_chat_history(current_model, *args):
78
  return current_model.load_chat_history(*args)
79
 
80
+ def upload_chat_history(current_model, file_src, username):
81
+ filename = file_src.name
82
+ return current_model.load_chat_history(filename, username)
83
+
84
  def set_token_upper_limit(current_model, *args):
85
  return current_model.set_token_upper_limit(*args)
86