From 8cfa01803fe248707fd9135a1eeff7d0e4c9b2ca Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 15 Mar 2025 12:08:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=89=88=E6=9C=AC=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=9B=B4=E6=96=B00.0.9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8F=AF=E8=A7=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/webui.py b/webui.py index e22f250ea..7d42a143e 100644 --- a/webui.py +++ b/webui.py @@ -12,6 +12,9 @@ is_share = False debug = True config_data = toml.load("config/bot_config.toml") +CONFIG_VERSION = config_data["inner"]["version"] +PARSED_CONFIG_VERSION = float(CONFIG_VERSION[2:]) + #============================================== #env环境配置文件读取部分 def parse_env_config(config_file): @@ -1099,6 +1102,16 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: enable_debug_output = gr.Checkbox(value=config_data['others']['enable_debug_output'], label="是否开启调试输出") with gr.Row(): enable_friend_chat = gr.Checkbox(value=config_data['others']['enable_friend_chat'], label="是否开启好友聊天") + if PARSED_CONFIG_VERSION > 0.8: + with gr.Row(): + gr.Markdown( + """### 远程统计设置\n + 测试功能,发送统计信息,主要是看全球有多少只麦麦 + """ + ) + with gr.Row(): + remote_status = gr.Checkbox(value=config_data['remote']['enable'], label="是否开启麦麦在线全球统计") + with gr.Row(): gr.Markdown( """### 中文错别字设置""" From 37eea8847af5dcbd18f5781756b8612ea16a80f7 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 15 Mar 2025 12:17:34 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=9B=B4=E6=96=B00.0.9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E4=BA=86=E4=B8=80=E4=BA=9B=E5=B0=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index 7d42a143e..22d858842 100644 --- a/webui.py +++ b/webui.py @@ -341,16 +341,19 @@ def save_memory_mood_config(t_build_memory_interval, t_memory_compress_rate, t_f logger.info("记忆和心情设置已保存到 bot_config.toml 文件中") return "记忆和心情设置已保存" -def save_other_config(t_keywords_reaction_enabled,t_enable_advance_output, t_enable_kuuki_read, t_enable_debug_output, t_enable_friend_chat, t_chinese_typo_enabled, t_error_rate, t_min_freq, t_tone_error_rate, t_word_replace_rate): +def save_other_config(t_keywords_reaction_enabled,t_enable_advance_output, t_enable_kuuki_read, t_enable_debug_output, t_enable_friend_chat, t_chinese_typo_enabled, t_error_rate, t_min_freq, t_tone_error_rate, t_word_replace_rate,t_remote_status): config_data['keywords_reaction']['enable'] = t_keywords_reaction_enabled config_data['others']['enable_advance_output'] = t_enable_advance_output config_data['others']['enable_kuuki_read'] = t_enable_kuuki_read config_data['others']['enable_debug_output'] = t_enable_debug_output + config_data['others']['enable_friend_chat'] = t_enable_friend_chat config_data["chinese_typo"]["enable"] = t_chinese_typo_enabled config_data["chinese_typo"]["error_rate"] = t_error_rate config_data["chinese_typo"]["min_freq"] = t_min_freq config_data["chinese_typo"]["tone_error_rate"] = t_tone_error_rate config_data["chinese_typo"]["word_replace_rate"] = t_word_replace_rate + if PARSED_CONFIG_VERSION > 0.8: + config_data["remote"]["enable"] = t_remote_status save_config_to_file(config_data) logger.info("其他设置已保存到 bot_config.toml 文件中") return "其他设置已保存" @@ -1112,6 +1115,7 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): remote_status = gr.Checkbox(value=config_data['remote']['enable'], label="是否开启麦麦在线全球统计") + with gr.Row(): gr.Markdown( """### 中文错别字设置""" @@ -1133,7 +1137,7 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): save_other_config_btn.click( save_other_config, - inputs=[keywords_reaction_enabled,enable_advance_output, enable_kuuki_read, enable_debug_output, enable_friend_chat, chinese_typo_enabled, error_rate, min_freq, tone_error_rate, word_replace_rate], + inputs=[keywords_reaction_enabled,enable_advance_output, enable_kuuki_read, enable_debug_output, enable_friend_chat, chinese_typo_enabled, error_rate, min_freq, tone_error_rate, word_replace_rate,remote_status], outputs=[save_other_config_message] ) app.queue().launch(#concurrency_count=511, max_size=1022 From dac1a6f769394f6804ac652fac3a6908314529ff Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 15 Mar 2025 12:24:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 22d858842..6cc2fa0c8 100644 --- a/webui.py +++ b/webui.py @@ -10,7 +10,11 @@ import json is_share = False debug = True -config_data = toml.load("config/bot_config.toml") +try: + config_data = toml.load("config/bot_config.toml") +except Exception as e: + logger.error(f"读取配置文件失败,请检查配置文件是否存在,错误信息为:{e}") + sys.exit(1) CONFIG_VERSION = config_data["inner"]["version"] PARSED_CONFIG_VERSION = float(CONFIG_VERSION[2:]) From c8b88b4f1f3724d8aaaa464275d77ad79e0ade17 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 15 Mar 2025 14:22:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=81=AB=E5=B1=B1=E5=BC=95=E6=93=8EAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 67 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/webui.py b/webui.py index 6cc2fa0c8..a65750111 100644 --- a/webui.py +++ b/webui.py @@ -10,11 +10,7 @@ import json is_share = False debug = True -try: - config_data = toml.load("config/bot_config.toml") -except Exception as e: - logger.error(f"读取配置文件失败,请检查配置文件是否存在,错误信息为:{e}") - sys.exit(1) +config_data = toml.load("config/bot_config.toml") CONFIG_VERSION = config_data["inner"]["version"] PARSED_CONFIG_VERSION = float(CONFIG_VERSION[2:]) @@ -76,8 +72,29 @@ def save_to_env_file(env_variables, filename=".env.prod"): f.write(f"{var[4:]}={value}\n") # 移除env_前缀 logger.info(f"配置已保存到 {filename}") + +#载入env文件并解析 env_config_file = ".env.prod" # 配置文件路径 env_config_data = parse_env_config(env_config_file) +if "env_VOLCENGINE_BASE_URL" in env_config_data: + logger.info("VOLCENGINE_BASE_URL 已存在,使用默认值") + env_config_data["env_VOLCENGINE_BASE_URL"] = "https://ark.cn-beijing.volces.com/api/v3" +else: + logger.info("VOLCENGINE_BASE_URL 不存在,已创建并使用默认值") + env_config_data["env_VOLCENGINE_BASE_URL"] = "https://ark.cn-beijing.volces.com/api/v3" + +if "env_VOLCENGINE_KEY" in env_config_data: + logger.info("VOLCENGINE_KEY 已存在,保持不变") +else: + logger.info("VOLCENGINE_KEY 不存在,已创建并使用默认值") + env_config_data["env_VOLCENGINE_KEY"] = "volc_key" +save_to_env_file(env_config_data, env_config_file) +MODEL_PROVIDER_LIST = [ + "VOLCENGINE", + "CHAT_ANY_WHERE", + "SILICONFLOW", + "DEEP_SEEK" +] #env读取保存结束 #============================================== @@ -166,7 +183,7 @@ def format_list_to_str(lst): #env保存函数 -def save_trigger(server_address, server_port, final_result_list,t_mongodb_host,t_mongodb_port,t_mongodb_database_name,t_chatanywhere_base_url,t_chatanywhere_key,t_siliconflow_base_url,t_siliconflow_key,t_deepseek_base_url,t_deepseek_key): +def save_trigger(server_address, server_port, final_result_list,t_mongodb_host,t_mongodb_port,t_mongodb_database_name,t_chatanywhere_base_url,t_chatanywhere_key,t_siliconflow_base_url,t_siliconflow_key,t_deepseek_base_url,t_deepseek_key,t_volcengine_base_url,t_volcengine_key): final_result_lists = format_list_to_str(final_result_list) env_config_data["env_HOST"] = server_address env_config_data["env_PORT"] = server_port @@ -180,6 +197,8 @@ def save_trigger(server_address, server_port, final_result_list,t_mongodb_host,t env_config_data["env_SILICONFLOW_KEY"] = t_siliconflow_key env_config_data["env_DEEP_SEEK_BASE_URL"] = t_deepseek_base_url env_config_data["env_DEEP_SEEK_KEY"] = t_deepseek_key + env_config_data["env_VOLCENGINE_BASE_URL"] = t_volcengine_base_url + env_config_data["env_VOLCENGINE_KEY"] = t_volcengine_key save_to_env_file(env_config_data) logger.success("配置已保存到 .env.prod 文件中") return "配置已保存" @@ -520,12 +539,24 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: value=env_config_data["env_DEEP_SEEK_KEY"], interactive=True ) + with gr.Row(): + volcengine_base_url = gr.Textbox( + label="VolcEngine的BaseURL", + value=env_config_data["env_VOLCENGINE_BASE_URL"], + interactive=True + ) + with gr.Row(): + volcengine_key = gr.Textbox( + label="VolcEngine的key", + value=env_config_data["env_VOLCENGINE_KEY"], + interactive=True + ) with gr.Row(): save_env_btn = gr.Button("保存环境配置",variant="primary") with gr.Row(): save_env_btn.click( save_trigger, - inputs=[server_address,server_port,final_result,mongodb_host,mongodb_port,mongodb_database_name,chatanywhere_base_url,chatanywhere_key,siliconflow_base_url,siliconflow_key,deepseek_base_url,deepseek_key], + inputs=[server_address,server_port,final_result,mongodb_host,mongodb_port,mongodb_database_name,chatanywhere_base_url,chatanywhere_key,siliconflow_base_url,siliconflow_key,deepseek_base_url,deepseek_key,volcengine_base_url,volcengine_key], outputs=[gr.Textbox( label="保存结果", interactive=False @@ -827,12 +858,20 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: gr.Markdown( """### 模型设置""" ) + with gr.Row(): + gr.Markdown( + """### 注意\n + 如果你是用的是火山引擎的API,建议查看[这篇文档](https://zxmucttizt8.feishu.cn/wiki/MQj7wp6dki6X8rkplApc2v6Enkd)中的修改火山API部分\n + 因为修改至火山API涉及到修改源码部分,由于自己修改源码造成的问题MaiMBot官方并不因此负责!\n + 感谢理解,感谢你使用MaiMBot + """ + ) with gr.Tabs(): with gr.TabItem("1-主要回复模型"): with gr.Row(): model1_name = gr.Textbox(value=config_data['model']['llm_reasoning']['name'], label="模型1的名称") with gr.Row(): - model1_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['llm_reasoning']['provider'], label="模型1(主要回复模型)提供商") + model1_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['llm_reasoning']['provider'], label="模型1(主要回复模型)提供商") with gr.Row(): model1_pri_in = gr.Number(value=config_data['model']['llm_reasoning']['pri_in'], label="模型1(主要回复模型)的输入价格(非必填,可以记录消耗)") with gr.Row(): @@ -841,12 +880,12 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): model2_name = gr.Textbox(value=config_data['model']['llm_normal']['name'], label="模型2的名称") with gr.Row(): - model2_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['llm_normal']['provider'], label="模型2提供商") + model2_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['llm_normal']['provider'], label="模型2提供商") with gr.TabItem("3-次要模型"): with gr.Row(): model3_name = gr.Textbox(value=config_data['model']['llm_reasoning_minor']['name'], label="模型3的名称") with gr.Row(): - model3_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['llm_reasoning_minor']['provider'], label="模型3提供商") + model3_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['llm_reasoning_minor']['provider'], label="模型3提供商") with gr.TabItem("4-情感&主题模型"): with gr.Row(): gr.Markdown( @@ -855,7 +894,7 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): emotion_model_name = gr.Textbox(value=config_data['model']['llm_emotion_judge']['name'], label="情感模型名称") with gr.Row(): - emotion_model_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['llm_emotion_judge']['provider'], label="情感模型提供商") + emotion_model_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['llm_emotion_judge']['provider'], label="情感模型提供商") with gr.Row(): gr.Markdown( """### 主题模型设置""" @@ -863,11 +902,11 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): topic_judge_model_name = gr.Textbox(value=config_data['model']['llm_topic_judge']['name'], label="主题判断模型名称") with gr.Row(): - topic_judge_model_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['llm_topic_judge']['provider'], label="主题判断模型提供商") + topic_judge_model_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['llm_topic_judge']['provider'], label="主题判断模型提供商") with gr.Row(): summary_by_topic_model_name = gr.Textbox(value=config_data['model']['llm_summary_by_topic']['name'], label="主题总结模型名称") with gr.Row(): - summary_by_topic_model_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['llm_summary_by_topic']['provider'], label="主题总结模型提供商") + summary_by_topic_model_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['llm_summary_by_topic']['provider'], label="主题总结模型提供商") with gr.TabItem("5-识图模型"): with gr.Row(): gr.Markdown( @@ -876,7 +915,7 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): vlm_model_name = gr.Textbox(value=config_data['model']['vlm']['name'], label="识图模型名称") with gr.Row(): - vlm_model_provider = gr.Dropdown(choices=["SILICONFLOW","DEEP_SEEK", "CHAT_ANY_WHERE"], value=config_data['model']['vlm']['provider'], label="识图模型提供商") + vlm_model_provider = gr.Dropdown(choices=MODEL_PROVIDER_LIST, value=config_data['model']['vlm']['provider'], label="识图模型提供商") with gr.Row(): save_model_btn = gr.Button("保存回复&模型设置",variant="primary", elem_id="save_model_btn") with gr.Row(): From 53232737f6e50251e1d0af63e584784ae6c76a75 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 15 Mar 2025 16:05:47 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E7=94=B1=E4=BA=8E=E7=89=88=E6=9C=AC=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=90=AF=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webui.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webui.py b/webui.py index a65750111..e9d831bc4 100644 --- a/webui.py +++ b/webui.py @@ -1178,6 +1178,8 @@ with gr.Blocks(title="MaimBot配置文件编辑") as app: with gr.Row(): save_other_config_message = gr.Textbox() with gr.Row(): + if PARSED_CONFIG_VERSION <= 0.8: + remote_status = gr.Checkbox(value=False,visible=False) save_other_config_btn.click( save_other_config, inputs=[keywords_reaction_enabled,enable_advance_output, enable_kuuki_read, enable_debug_output, enable_friend_chat, chinese_typo_enabled, error_rate, min_freq, tone_error_rate, word_replace_rate,remote_status],