Skip to content

Commit 40a0cc7

Browse files
committed
feat: 打开网页时创建新对话,而不是加载最晚的那一条
1 parent 4cadbd1 commit 40a0cc7

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

ChuanhuChatbot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def create_greeting(request: gr.Request):
511511
loaded_stuff = current_model.auto_load()
512512
else:
513513
loaded_stuff = [gr.update(), gr.update(), gr.Chatbot.update(label=MODELS[DEFAULT_MODEL]), current_model.single_turn, current_model.temperature, current_model.top_p, current_model.n_choices, current_model.stop_sequence, current_model.token_upper_limit, current_model.max_generation_token, current_model.presence_penalty, current_model.frequency_penalty, current_model.logit_bias, current_model.user_identifier]
514-
return user_info, user_name, current_model, toggle_like_btn_visibility(DEFAULT_MODEL), *loaded_stuff, init_history_list(user_name)
514+
return user_info, user_name, current_model, toggle_like_btn_visibility(DEFAULT_MODEL), *loaded_stuff, init_history_list(user_name, prepend=current_model.history_file_path[:-5])
515515
demo.load(create_greeting, inputs=None, outputs=[
516516
user_info, user_name, current_model, like_dislike_area, saveFileName, systemPromptTxt, chatbot, single_turn_checkbox, temperature_slider, top_p_slider, n_choices_slider, stop_sequence_txt, max_context_length_slider, max_generation_slider, presence_penalty_slider, frequency_penalty_slider, logit_bias_txt, user_identifier_txt, historySelectList], api_name="load")
517517
chatgpt_predict_args = dict(

modules/models/base_model.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,9 @@ def reset(self, remain_system_prompt=False):
791791
self.interrupted = False
792792
self.history_file_path = new_auto_history_filename(self.user_name)
793793
history_name = self.history_file_path[:-5]
794-
choices = [history_name] + get_history_names(self.user_name)
794+
choices = get_history_names(self.user_name)
795+
if history_name not in choices:
796+
choices.insert(0, history_name)
795797
system_prompt = self.system_prompt if remain_system_prompt else ""
796798

797799
self.single_turn = self.default_single_turn
@@ -893,9 +895,8 @@ def auto_name_chat_history(
893895
return gr.update()
894896

895897
def auto_save(self, chatbot=None):
896-
if chatbot is None:
897-
chatbot = self.chatbot
898-
save_file(self.history_file_path, self, chatbot)
898+
if chatbot is not None:
899+
save_file(self.history_file_path, self, chatbot)
899900

900901
def export_markdown(self, filename, chatbot):
901902
if filename == "":
@@ -1036,11 +1037,7 @@ def delete_chat_history(self, filename):
10361037
)
10371038

10381039
def auto_load(self):
1039-
filepath = get_history_filepath(self.user_name)
1040-
if not filepath:
1041-
self.history_file_path = new_auto_history_filename(self.user_name)
1042-
else:
1043-
self.history_file_path = filepath
1040+
self.history_file_path = new_auto_history_filename(self.user_name)
10441041
return self.load_chat_history()
10451042

10461043
def like(self):

modules/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,10 @@ def get_history_list(user_name=""):
486486
return gr.Radio.update(choices=history_names)
487487

488488

489-
def init_history_list(user_name=""):
489+
def init_history_list(user_name="", prepend=None):
490490
history_names = get_history_names(user_name)
491+
if prepend is not None and prepend not in history_names:
492+
history_names.insert(0, prepend)
491493
return gr.Radio.update(
492494
choices=history_names, value=history_names[0] if history_names else ""
493495
)

0 commit comments

Comments
 (0)