From 6db889580da01b6e032e80a4f2b076e9493b552d Mon Sep 17 00:00:00 2001 From: UnCLAS-Prommer Date: Sat, 14 Feb 2026 23:52:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B9=E4=BE=BF=E6=B6=88=E6=81=AF=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=A3=80=E6=9F=A5=E7=9A=84property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data_models/message_component_model.py | 46 +++++++++++++++++++ src/config/official_configs.py | 43 +++++++++++------ 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/src/common/data_models/message_component_model.py b/src/common/data_models/message_component_model.py index 7bb132b8..1d7083d0 100644 --- a/src/common/data_models/message_component_model.py +++ b/src/common/data_models/message_component_model.py @@ -13,6 +13,12 @@ logger = get_logger("base_message_component_model") class BaseMessageComponentModel(ABC): + @property + @abstractmethod + def format_name(self) -> str: + """消息组件的格式名称,用于标识该组件的类型""" + raise NotImplementedError + @abstractmethod async def to_seg(self) -> Seg: """将消息组件转换为 maim_message.Seg 对象""" @@ -34,6 +40,11 @@ class ByteComponent: class TextComponent(BaseMessageComponentModel): """文本组件,包含一个文本消息的内容""" + + @property + def format_name(self) -> str: + return "text" + def __init__(self, text: str): self.text = text assert isinstance(text, str), "TextComponent 的 text 必须是字符串类型" @@ -44,6 +55,11 @@ class TextComponent(BaseMessageComponentModel): class ImageComponent(BaseMessageComponentModel, ByteComponent): """图片组件,包含一个图片消息的二进制数据和一个唯一标识该图片消息的 hash 值""" + + @property + def format_name(self) -> str: + return "image" + async def load_image_binary(self): if not self.binary_data: raise NotImplementedError @@ -56,6 +72,11 @@ class ImageComponent(BaseMessageComponentModel, ByteComponent): class EmojiComponent(BaseMessageComponentModel, ByteComponent): """表情组件,包含一个表情消息的二进制数据和一个唯一标识该表情消息的 hash 值""" + + @property + def format_name(self) -> str: + return "emoji" + async def load_emoji_binary(self) -> None: """ 加载表情的二进制数据,如果 binary_data 为空,则通过 emoji_hash 从表情管理器加载 @@ -85,6 +106,11 @@ class EmojiComponent(BaseMessageComponentModel, ByteComponent): class VoiceComponent(BaseMessageComponentModel, ByteComponent): """语音组件,包含一个语音消息的二进制数据和一个唯一标识该语音消息的 hash 值""" + + @property + def format_name(self) -> str: + return "voice" + async def load_voice_binary(self) -> None: if not self.binary_data: from src.common.utils.utils_file import FileUtils @@ -103,6 +129,11 @@ class VoiceComponent(BaseMessageComponentModel, ByteComponent): class AtComponent(BaseMessageComponentModel): """@组件,包含一个被@的用户的ID,用于表示该组件是一个@某人的消息片段""" + + @property + def format_name(self) -> str: + return "at" + def __init__(self, target_user_id: str) -> None: self.target_user_id = target_user_id """目标用户ID""" @@ -114,6 +145,11 @@ class AtComponent(BaseMessageComponentModel): class ReplyComponent(BaseMessageComponentModel): """回复组件,包含一个回复消息的 ID,用于表示该组件是对哪条消息的回复""" + + @property + def format_name(self) -> str: + return "reply" + def __init__(self, target_message_id: str) -> None: assert isinstance(target_message_id, str), "ReplyComponent 的 target_message_id 必须是字符串类型" self.target_message_id = target_message_id @@ -125,6 +161,11 @@ class ReplyComponent(BaseMessageComponentModel): class ForwardNodeComponent(BaseMessageComponentModel): """转发节点消息组件,包含一个转发节点的消息,所有组件按照消息顺序排列""" + + @property + def format_name(self) -> str: + return "forward_node" + def __init__(self, forward_components: List["ForwardComponent"]): self.forward_components = forward_components """节点的消息组件列表,按照消息顺序排列""" @@ -165,6 +206,11 @@ StandardMessageComponents = Union[ class ForwardComponent(BaseMessageComponentModel): """转发组件,包含一个转发消息中的一个节点的信息,包括发送者信息和该节点的消息内容""" + + @property + def format_name(self) -> str: + return "forward" + def __init__( self, user_nickname: str, diff --git a/src/config/official_configs.py b/src/config/official_configs.py index deb3e518..a1e44d64 100644 --- a/src/config/official_configs.py +++ b/src/config/official_configs.py @@ -18,15 +18,16 @@ class ExampleConfig(ConfigBase): class BotConfig(ConfigBase): """机器人配置类""" + platform: str = "" """平台""" - + qq_account: int = 0 """QQ账号""" - + platforms: list[str] = Field(default_factory=lambda: []) """其他平台""" - + nickname: str = "麦麦" """机器人昵称""" @@ -49,11 +50,13 @@ class PersonalityConfig(ConfigBase): multiple_probability: float = 0.3 """每次构建回复时,从 multiple_reply_style 中随机替换 reply_style 的概率(0.0-1.0)""" - plan_style: str = """1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 -2.如果相同的action已经被执行,请不要重复执行该action -3.如果有人对你感到厌烦,请减少回复 -4.如果有人在追问你,或者话题没有说完,请你继续回复 -5.请分析哪些对话是和你说的,哪些是其他人之间的互动,不要误认为其他人之间的互动是和你说的""" + plan_style: str = ( + "1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用" + "2.如果相同的action已经被执行,请不要重复执行该action" + "3.如果有人对你感到厌烦,请减少回复" + "4.如果有人在追问你,或者话题没有说完,请你继续回复" + "5.请分析哪些对话是和你说的,哪些是其他人之间的互动,不要误认为其他人之间的互动是和你说的" + ) """_wrap_麦麦的说话规则和行为规则""" visual_style: str = "请用中文描述这张图片的内容。如果有文字,请把文字描述概括出来,请留意其主题,直观感受,输出为一段平文本,最多30字,请注意不要分点,就输出一段文本" @@ -142,6 +145,12 @@ class ChatConfig(ConfigBase): class MessageReceiveConfig(ConfigBase): """消息接收配置类""" + image_parse_threshold: int = 5 + """ + 当消息中图片数量不超过此阈值时,启用图片解析功能,将图片内容解析为文本后再进行处理。 + 当消息中图片数量超过此阈值时,为了避免过度解析导致的性能问题,将跳过图片解析,直接进行处理。 + """ + ban_words: set[str] = Field(default_factory=lambda: set()) """过滤词列表""" @@ -497,10 +506,11 @@ class ExtraPromptItem(ConfigBase): class ExperimentalConfig(ConfigBase): """实验功能配置类""" - private_plan_style: str = """ -1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用 -2.如果相同的内容已经被执行,请不要重复执行 -3.某句话如果已经被回复过,不要重复回复""" + private_plan_style: str = ( + "1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用" + "2.如果相同的内容已经被执行,请不要重复执行" + "3.某句话如果已经被回复过,不要重复回复" + ) """_wrap_私聊说话规则,行为风格(实验性功能)""" chat_prompts: list[ExtraPromptItem] = Field(default_factory=lambda: []) @@ -512,9 +522,10 @@ class ExperimentalConfig(ConfigBase): class MaimMessageConfig(ConfigBase): """maim_message配置类""" + ws_server_host: str = "127.0.0.1" """旧版基于WS的服务器主机地址""" - + ws_server_port: int = 8080 """旧版基于WS的服务器端口号""" @@ -628,6 +639,7 @@ class DreamConfig(ConfigBase): raise ValueError(f"first_delay_seconds 不能为负数,当前值: {self.first_delay_seconds}") return super().model_post_init(context) + class WebUIConfig(ConfigBase): """WebUI配置类""" @@ -655,13 +667,14 @@ class WebUIConfig(ConfigBase): enable_paragraph_content: bool = False """是否在知识图谱中加载段落完整内容(需要加载embedding store,会占用额外内存)""" + class DatabaseConfig(ConfigBase): """数据库配置类""" - + save_binary_data: bool = False """ 是否将消息中的二进制数据保存为独立文件 若启用,消息中的语音等二进制数据将会保存为独立文件,并在消息中以特殊标记替代。启用会导致数据文件夹体积增大,但可以实现二次识别等功能。 若禁用,则消息中的二进制将会在识别后删除,并在消息中使用识别结果替代,无法二次识别 该配置项仅影响新存储的消息,已有消息不会受到影响 - """ \ No newline at end of file + """