From 12e759f3ad5a3c4d9b782aa01b55ec73aa88ad80 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sun, 2 Mar 2025 20:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=8E=E5=B1=B1=E4=BF=AE=E8=A1=A5=E6=9C=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改了bot_toml加载逻辑 --- .gitignore | 2 +- config/bot_config.toml | 11 ++--- src/plugins/chat/config.py | 72 +++++++++++++++++++++++++----- src/plugins/chat/cq_code.py | 2 +- src/plugins/chat/prompt_builder.py | 4 +- 5 files changed, 72 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 8df5d72a..a9cdc192 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ reasoning_window.bat queue_update.txt memory_graph.gml .env.* - +config/bot_config_dev.toml # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/config/bot_config.toml b/config/bot_config.toml index d668fcf5..4863da24 100644 --- a/config/bot_config.toml +++ b/config/bot_config.toml @@ -1,5 +1,5 @@ [bot] -qq = 123456 #填入你的机器人QQ +qq = 123 #填入你的机器人QQ nickname = "麦麦" #你希望bot被称呼的名字 [message] @@ -17,7 +17,7 @@ enable_pic_translate = false [response] api_using = "siliconflow" # 选择大模型API,可选值为siliconflow,deepseek,建议使用siliconflow,因为识图api目前只支持siliconflow的deepseek-vl2模型 -api_paid = false #是否使用付费api,目前此选项只影响siliconflow,其deepseek模型的api分为可用赠送余额和不可以用的,此选项为false时使用赠送余额 +api_paid = true #是否使用付费api,目前此选项只影响siliconflow,其deepseek模型的api分为可用赠送余额和不可以用的,此选项为false时使用赠送余额 model_r1_probability = 0.8 # 麦麦回答时选择R1模型的概率 model_v3_probability = 0.1 # 麦麦回答时选择V3模型的概率 model_r1_distill_probability = 0.1 # 麦麦回答时选择R1蒸馏模型的概率 @@ -34,13 +34,14 @@ enable_advance_output = true # 开启后输出更多日志,false关闭true开启 [groups] talk_allowed = [ - 123456,12345678 + 123, + 123, ] #可以回复消息的群 talk_frequency_down = [ - 123456,12345678 + ] #降低回复频率的群 ban_user_id = [ - 123456,12345678 + ] #禁止回复消息的QQ号 diff --git a/src/plugins/chat/config.py b/src/plugins/chat/config.py index 54d12540..b85cbc2e 100644 --- a/src/plugins/chat/config.py +++ b/src/plugins/chat/config.py @@ -47,20 +47,59 @@ class BotConfig: enable_kuuki_read: bool = True # 是否启用读空气功能 @staticmethod - def get_default_config_path() -> str: - """获取默认配置文件路径""" + def get_config_dir() -> str: + """获取配置文件目录""" current_dir = os.path.dirname(os.path.abspath(__file__)) root_dir = os.path.abspath(os.path.join(current_dir, '..', '..', '..')) config_dir = os.path.join(root_dir, 'config') - return os.path.join(config_dir, 'bot_config.toml') + if not os.path.exists(config_dir): + os.makedirs(config_dir) + return config_dir + + @staticmethod + def create_default_config(config_path: str) -> None: + """创建默认配置文件""" + default_config = """[bot] +qq = 1 # 填入你的机器人QQ +nickname = "麦麦" # 你希望bot被称呼的名字 + +[message] +min_text_length = 2 # 与麦麦聊天时麦麦只会回答文本大于等于此数的消息 +max_context_size = 15 # 麦麦获得的上下文数量,超出数量后自动丢弃 +emoji_chance = 0.2 # 麦麦使用表情包的概率 + +[emoji] +check_interval = 120 +register_interval = 10 + +[cq_code] +enable_pic_translate = false + +[response] +api_using = "siliconflow" # 选择大模型API,可选值为siliconflow,deepseek +api_paid = false # 是否使用付费api +model_r1_probability = 0.8 # 麦麦回答时选择R1模型的概率 +model_v3_probability = 0.1 # 麦麦回答时选择V3模型的概率 +model_r1_distill_probability = 0.1 # 麦麦回答时选择R1蒸馏模型的概率 + +[memory] +build_memory_interval = 300 # 记忆构建间隔 + +[others] +enable_advance_output = false # 开启后输出更多日志 + +[groups] +talk_allowed = [] # 可以回复消息的群 +talk_frequency_down = [] # 降低回复频率的群 +ban_user_id = [] # 禁止回复消息的QQ号 +""" + with open(config_path, "w", encoding="utf-8") as f: + f.write(default_config) + logger.success(f"已创建默认配置文件: {config_path}") @classmethod def load_config(cls, config_path: str = None) -> "BotConfig": """从TOML配置文件加载配置""" - if config_path is None: - config_path = cls.get_default_config_path() - logger.info(f"使用默认配置文件路径: {config_path}") - config = cls() if os.path.exists(config_path): with open(config_path, "rb") as f: @@ -119,12 +158,25 @@ class BotConfig: return config # 获取配置文件路径 -bot_config_path = BotConfig.get_default_config_path() -config_dir = os.path.dirname(bot_config_path) -logger.info(f"尝试从 {bot_config_path} 加载机器人配置") +bot_config_floder_path = BotConfig.get_config_dir() +print(f"正在品鉴配置文件目录: {bot_config_floder_path}") +bot_config_path = os.path.join(bot_config_floder_path, "bot_config_dev.toml") +if not os.path.exists(bot_config_path): + # 如果开发环境配置文件不存在,则使用默认配置文件 + bot_config_path = os.path.join(bot_config_floder_path, "bot_config.toml") + logger.info("使用默认配置文件") +else: + logger.info("已找到开发环境配置文件") + global_config = BotConfig.load_config(config_path=bot_config_path) + +# config_dir = os.path.dirname(bot_config_path) + +# logger.info(f"尝试从 {bot_config_path} 加载机器人配置") +# global_config = BotConfig.load_config(config_path=bot_config_path) + @dataclass class LLMConfig: """机器人配置类""" diff --git a/src/plugins/chat/cq_code.py b/src/plugins/chat/cq_code.py index ae5d8a25..386124c9 100644 --- a/src/plugins/chat/cq_code.py +++ b/src/plugins/chat/cq_code.py @@ -349,7 +349,7 @@ class CQCode: # 创建Message对象 from .message import Message if self.reply_message == None: - print(f"\033[1;31m[错误]\033[0m 回复消息为空") + # print(f"\033[1;31m[错误]\033[0m 回复消息为空") return '[回复某人消息]' if self.reply_message.sender.user_id: diff --git a/src/plugins/chat/prompt_builder.py b/src/plugins/chat/prompt_builder.py index 01fe3e82..27222941 100644 --- a/src/plugins/chat/prompt_builder.py +++ b/src/plugins/chat/prompt_builder.py @@ -150,9 +150,9 @@ class PromptBuilder: prompt_personality = '' personality_choice = random.random() if personality_choice < 4/6: # 第一种人格 - prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},曾经是一个学习地质的女大学生,现在学习心理学和脑科学,你会刷贴吧,你正在浏览qq群,{promt_info_prompt}, + prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},现在学习心理学和脑科学,你会刷贴吧,你正在浏览qq群,{promt_info_prompt}, 现在请你给出日常且口语化的回复,平淡一些,尽量简短一些。{is_bot_prompt} - 请注意把握群里的聊天内容,不要回复的太有条理,可以有个性。''' + 请注意把握群里的聊天内容,不要刻意突出自身学科背景,不要回复的太有条理,可以有个性。''' elif personality_choice < 1: # 第二种人格 prompt_personality = f'''{activate_prompt}你的网名叫{global_config.BOT_NICKNAME},是一个女大学生,你有黑色头发,你会刷小红书, 你正在浏览qq群,{promt_info_prompt},