From a0b69681650c456414fd76be32b05bf91fa15220 Mon Sep 17 00:00:00 2001 From: Keldos Date: Sun, 5 May 2024 16:36:31 +0800 Subject: [PATCH] feat: model description move to chatbot header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复没desc也显示info的错误 --- ChuanhuChatbot.py | 11 ++++-- modules/models/base_model.py | 4 +-- modules/models/models.py | 5 +-- web_assets/html/chatbot_header_btn.html | 20 +++++++++-- web_assets/javascript/ChuanhuChat.js | 37 +++++++++++++++++---- web_assets/stylesheet/ChuanhuChat.css | 6 ++++ web_assets/stylesheet/custom-components.css | 15 ++++++++- 7 files changed, 81 insertions(+), 17 deletions(-) diff --git a/ChuanhuChatbot.py b/ChuanhuChatbot.py index 45a88494..51f36df4 100644 --- a/ChuanhuChatbot.py +++ b/ChuanhuChatbot.py @@ -140,7 +140,7 @@ def create_new_model(): show_label=False, avatar_images=[config.user_avatar, config.bot_avatar], show_share_button=False, - placeholder=i18n(MODEL_METADATA[MODELS[DEFAULT_MODEL]]["description"]) + # placeholder=i18n(MODEL_METADATA[MODELS[DEFAULT_MODEL]]["description"]) ) with gr.Row(elem_id="chatbot-footer"): with gr.Column(elem_id="chatbot-input-box"): @@ -199,6 +199,11 @@ def create_new_model(): with gr.Tabs(elem_id="chuanhu-toolbox-tabs"): with gr.Tab(label=i18n("对话")): with gr.Accordion(label=i18n("模型"), open=not HIDE_MY_KEY, visible=not HIDE_MY_KEY): + modelDescription = gr.Markdown( + elem_id="gr-model-description", + value=i18n(MODEL_METADATA[MODELS[DEFAULT_MODEL]]["description"]), + visible=False, + ) keyTxt = gr.Textbox( show_label=True, placeholder=f"Your API-key...", @@ -655,13 +660,13 @@ def create_greeting(request: gr.Request): single_turn_checkbox.change( set_single_turn, [current_model, single_turn_checkbox], None, show_progress=False) model_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, top_p_slider, systemPromptTxt, user_name, current_model], [ - current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt], show_progress=True, api_name="get_model") + current_model, status_display, chatbot, lora_select_dropdown, user_api_key, keyTxt, modelDescription], show_progress=True, api_name="get_model") model_select_dropdown.change(toggle_like_btn_visibility, [model_select_dropdown], [ like_dislike_area], show_progress=False) # model_select_dropdown.change( # toggle_file_type, [model_select_dropdown], [index_files], show_progress=False) lora_select_dropdown.change(get_model, [model_select_dropdown, lora_select_dropdown, user_api_key, temperature_slider, - top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot], show_progress=True) + top_p_slider, systemPromptTxt, user_name, current_model], [current_model, status_display, chatbot, modelDescription], show_progress=True) # Template systemPromptTxt.change(set_system_prompt, [ diff --git a/modules/models/base_model.py b/modules/models/base_model.py index 704c1e86..17d7b8fe 100644 --- a/modules/models/base_model.py +++ b/modules/models/base_model.py @@ -1052,7 +1052,7 @@ def load_chat_history(self, new_history_file_path=None): return ( os.path.basename(self.history_file_path)[:-5], saved_json["system"], - gr.update(placeholder=i18n(self.description), value=saved_json["chatbot"]), + gr.update(value=saved_json["chatbot"]), self.single_turn, self.temperature, self.top_p, @@ -1072,7 +1072,7 @@ def load_chat_history(self, new_history_file_path=None): return ( os.path.basename(self.history_file_path), self.system_prompt, - gr.update(placeholder=i18n(self.description), value=[]), + gr.update(value=[]), self.single_turn, self.temperature, self.top_p, diff --git a/modules/models/models.py b/modules/models/models.py index f4731d18..e3131f45 100644 --- a/modules/models/models.py +++ b/modules/models/models.py @@ -151,15 +151,16 @@ def get_model( import traceback traceback.print_exc() msg = f"{STANDARD_ERROR_MSG}: {e}" + modelDescription = i18n(model.description) presudo_key = hide_middle_chars(access_key) if original_model is not None and model is not None: model.history = original_model.history model.history_file_path = original_model.history_file_path model.system_prompt = original_model.system_prompt if dont_change_lora_selector: - return model, msg, gr.update(label=model_name, placeholder=i18n(model.description)), gr.update(), access_key, presudo_key + return model, msg, gr.update(label=model_name), gr.update(), access_key, presudo_key, modelDescription else: - return model, msg, gr.update(label=model_name, placeholder=i18n(model.description)), gr.Dropdown(choices=lora_choices, visible=lora_selector_visibility), access_key, presudo_key + return model, msg, gr.update(label=model_name), gr.Dropdown(choices=lora_choices, visible=lora_selector_visibility), access_key, presudo_key, modelDescription if __name__ == "__main__": diff --git a/web_assets/html/chatbot_header_btn.html b/web_assets/html/chatbot_header_btn.html index 2dda88fd..bf76d696 100644 --- a/web_assets/html/chatbot_header_btn.html +++ b/web_assets/html/chatbot_header_btn.html @@ -1,5 +1,21 @@
-
+
+ +