mirror of https://github.com/Mai-with-u/MaiBot.git
方便消息格式检查的property
parent
dc36542403
commit
6db889580d
|
|
@ -13,6 +13,12 @@ logger = get_logger("base_message_component_model")
|
||||||
|
|
||||||
|
|
||||||
class BaseMessageComponentModel(ABC):
|
class BaseMessageComponentModel(ABC):
|
||||||
|
@property
|
||||||
|
@abstractmethod
|
||||||
|
def format_name(self) -> str:
|
||||||
|
"""消息组件的格式名称,用于标识该组件的类型"""
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def to_seg(self) -> Seg:
|
async def to_seg(self) -> Seg:
|
||||||
"""将消息组件转换为 maim_message.Seg 对象"""
|
"""将消息组件转换为 maim_message.Seg 对象"""
|
||||||
|
|
@ -34,6 +40,11 @@ class ByteComponent:
|
||||||
|
|
||||||
class TextComponent(BaseMessageComponentModel):
|
class TextComponent(BaseMessageComponentModel):
|
||||||
"""文本组件,包含一个文本消息的内容"""
|
"""文本组件,包含一个文本消息的内容"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "text"
|
||||||
|
|
||||||
def __init__(self, text: str):
|
def __init__(self, text: str):
|
||||||
self.text = text
|
self.text = text
|
||||||
assert isinstance(text, str), "TextComponent 的 text 必须是字符串类型"
|
assert isinstance(text, str), "TextComponent 的 text 必须是字符串类型"
|
||||||
|
|
@ -44,6 +55,11 @@ class TextComponent(BaseMessageComponentModel):
|
||||||
|
|
||||||
class ImageComponent(BaseMessageComponentModel, ByteComponent):
|
class ImageComponent(BaseMessageComponentModel, ByteComponent):
|
||||||
"""图片组件,包含一个图片消息的二进制数据和一个唯一标识该图片消息的 hash 值"""
|
"""图片组件,包含一个图片消息的二进制数据和一个唯一标识该图片消息的 hash 值"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "image"
|
||||||
|
|
||||||
async def load_image_binary(self):
|
async def load_image_binary(self):
|
||||||
if not self.binary_data:
|
if not self.binary_data:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
@ -56,6 +72,11 @@ class ImageComponent(BaseMessageComponentModel, ByteComponent):
|
||||||
|
|
||||||
class EmojiComponent(BaseMessageComponentModel, ByteComponent):
|
class EmojiComponent(BaseMessageComponentModel, ByteComponent):
|
||||||
"""表情组件,包含一个表情消息的二进制数据和一个唯一标识该表情消息的 hash 值"""
|
"""表情组件,包含一个表情消息的二进制数据和一个唯一标识该表情消息的 hash 值"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "emoji"
|
||||||
|
|
||||||
async def load_emoji_binary(self) -> None:
|
async def load_emoji_binary(self) -> None:
|
||||||
"""
|
"""
|
||||||
加载表情的二进制数据,如果 binary_data 为空,则通过 emoji_hash 从表情管理器加载
|
加载表情的二进制数据,如果 binary_data 为空,则通过 emoji_hash 从表情管理器加载
|
||||||
|
|
@ -85,6 +106,11 @@ class EmojiComponent(BaseMessageComponentModel, ByteComponent):
|
||||||
|
|
||||||
class VoiceComponent(BaseMessageComponentModel, ByteComponent):
|
class VoiceComponent(BaseMessageComponentModel, ByteComponent):
|
||||||
"""语音组件,包含一个语音消息的二进制数据和一个唯一标识该语音消息的 hash 值"""
|
"""语音组件,包含一个语音消息的二进制数据和一个唯一标识该语音消息的 hash 值"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "voice"
|
||||||
|
|
||||||
async def load_voice_binary(self) -> None:
|
async def load_voice_binary(self) -> None:
|
||||||
if not self.binary_data:
|
if not self.binary_data:
|
||||||
from src.common.utils.utils_file import FileUtils
|
from src.common.utils.utils_file import FileUtils
|
||||||
|
|
@ -103,6 +129,11 @@ class VoiceComponent(BaseMessageComponentModel, ByteComponent):
|
||||||
|
|
||||||
class AtComponent(BaseMessageComponentModel):
|
class AtComponent(BaseMessageComponentModel):
|
||||||
"""@组件,包含一个被@的用户的ID,用于表示该组件是一个@某人的消息片段"""
|
"""@组件,包含一个被@的用户的ID,用于表示该组件是一个@某人的消息片段"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "at"
|
||||||
|
|
||||||
def __init__(self, target_user_id: str) -> None:
|
def __init__(self, target_user_id: str) -> None:
|
||||||
self.target_user_id = target_user_id
|
self.target_user_id = target_user_id
|
||||||
"""目标用户ID"""
|
"""目标用户ID"""
|
||||||
|
|
@ -114,6 +145,11 @@ class AtComponent(BaseMessageComponentModel):
|
||||||
|
|
||||||
class ReplyComponent(BaseMessageComponentModel):
|
class ReplyComponent(BaseMessageComponentModel):
|
||||||
"""回复组件,包含一个回复消息的 ID,用于表示该组件是对哪条消息的回复"""
|
"""回复组件,包含一个回复消息的 ID,用于表示该组件是对哪条消息的回复"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "reply"
|
||||||
|
|
||||||
def __init__(self, target_message_id: str) -> None:
|
def __init__(self, target_message_id: str) -> None:
|
||||||
assert isinstance(target_message_id, str), "ReplyComponent 的 target_message_id 必须是字符串类型"
|
assert isinstance(target_message_id, str), "ReplyComponent 的 target_message_id 必须是字符串类型"
|
||||||
self.target_message_id = target_message_id
|
self.target_message_id = target_message_id
|
||||||
|
|
@ -125,6 +161,11 @@ class ReplyComponent(BaseMessageComponentModel):
|
||||||
|
|
||||||
class ForwardNodeComponent(BaseMessageComponentModel):
|
class ForwardNodeComponent(BaseMessageComponentModel):
|
||||||
"""转发节点消息组件,包含一个转发节点的消息,所有组件按照消息顺序排列"""
|
"""转发节点消息组件,包含一个转发节点的消息,所有组件按照消息顺序排列"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "forward_node"
|
||||||
|
|
||||||
def __init__(self, forward_components: List["ForwardComponent"]):
|
def __init__(self, forward_components: List["ForwardComponent"]):
|
||||||
self.forward_components = forward_components
|
self.forward_components = forward_components
|
||||||
"""节点的消息组件列表,按照消息顺序排列"""
|
"""节点的消息组件列表,按照消息顺序排列"""
|
||||||
|
|
@ -165,6 +206,11 @@ StandardMessageComponents = Union[
|
||||||
|
|
||||||
class ForwardComponent(BaseMessageComponentModel):
|
class ForwardComponent(BaseMessageComponentModel):
|
||||||
"""转发组件,包含一个转发消息中的一个节点的信息,包括发送者信息和该节点的消息内容"""
|
"""转发组件,包含一个转发消息中的一个节点的信息,包括发送者信息和该节点的消息内容"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format_name(self) -> str:
|
||||||
|
return "forward"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
user_nickname: str,
|
user_nickname: str,
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class ExampleConfig(ConfigBase):
|
||||||
|
|
||||||
class BotConfig(ConfigBase):
|
class BotConfig(ConfigBase):
|
||||||
"""机器人配置类"""
|
"""机器人配置类"""
|
||||||
|
|
||||||
platform: str = ""
|
platform: str = ""
|
||||||
"""平台"""
|
"""平台"""
|
||||||
|
|
||||||
|
|
@ -49,11 +50,13 @@ class PersonalityConfig(ConfigBase):
|
||||||
multiple_probability: float = 0.3
|
multiple_probability: float = 0.3
|
||||||
"""每次构建回复时,从 multiple_reply_style 中随机替换 reply_style 的概率(0.0-1.0)"""
|
"""每次构建回复时,从 multiple_reply_style 中随机替换 reply_style 的概率(0.0-1.0)"""
|
||||||
|
|
||||||
plan_style: str = """1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用
|
plan_style: str = (
|
||||||
2.如果相同的action已经被执行,请不要重复执行该action
|
"1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用"
|
||||||
3.如果有人对你感到厌烦,请减少回复
|
"2.如果相同的action已经被执行,请不要重复执行该action"
|
||||||
4.如果有人在追问你,或者话题没有说完,请你继续回复
|
"3.如果有人对你感到厌烦,请减少回复"
|
||||||
5.请分析哪些对话是和你说的,哪些是其他人之间的互动,不要误认为其他人之间的互动是和你说的"""
|
"4.如果有人在追问你,或者话题没有说完,请你继续回复"
|
||||||
|
"5.请分析哪些对话是和你说的,哪些是其他人之间的互动,不要误认为其他人之间的互动是和你说的"
|
||||||
|
)
|
||||||
"""_wrap_麦麦的说话规则和行为规则"""
|
"""_wrap_麦麦的说话规则和行为规则"""
|
||||||
|
|
||||||
visual_style: str = "请用中文描述这张图片的内容。如果有文字,请把文字描述概括出来,请留意其主题,直观感受,输出为一段平文本,最多30字,请注意不要分点,就输出一段文本"
|
visual_style: str = "请用中文描述这张图片的内容。如果有文字,请把文字描述概括出来,请留意其主题,直观感受,输出为一段平文本,最多30字,请注意不要分点,就输出一段文本"
|
||||||
|
|
@ -142,6 +145,12 @@ class ChatConfig(ConfigBase):
|
||||||
class MessageReceiveConfig(ConfigBase):
|
class MessageReceiveConfig(ConfigBase):
|
||||||
"""消息接收配置类"""
|
"""消息接收配置类"""
|
||||||
|
|
||||||
|
image_parse_threshold: int = 5
|
||||||
|
"""
|
||||||
|
当消息中图片数量不超过此阈值时,启用图片解析功能,将图片内容解析为文本后再进行处理。
|
||||||
|
当消息中图片数量超过此阈值时,为了避免过度解析导致的性能问题,将跳过图片解析,直接进行处理。
|
||||||
|
"""
|
||||||
|
|
||||||
ban_words: set[str] = Field(default_factory=lambda: set())
|
ban_words: set[str] = Field(default_factory=lambda: set())
|
||||||
"""过滤词列表"""
|
"""过滤词列表"""
|
||||||
|
|
||||||
|
|
@ -497,10 +506,11 @@ class ExtraPromptItem(ConfigBase):
|
||||||
class ExperimentalConfig(ConfigBase):
|
class ExperimentalConfig(ConfigBase):
|
||||||
"""实验功能配置类"""
|
"""实验功能配置类"""
|
||||||
|
|
||||||
private_plan_style: str = """
|
private_plan_style: str = (
|
||||||
1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用
|
"1.思考**所有**的可用的action中的**每个动作**是否符合当下条件,如果动作使用条件符合聊天内容就使用"
|
||||||
2.如果相同的内容已经被执行,请不要重复执行
|
"2.如果相同的内容已经被执行,请不要重复执行"
|
||||||
3.某句话如果已经被回复过,不要重复回复"""
|
"3.某句话如果已经被回复过,不要重复回复"
|
||||||
|
)
|
||||||
"""_wrap_私聊说话规则,行为风格(实验性功能)"""
|
"""_wrap_私聊说话规则,行为风格(实验性功能)"""
|
||||||
|
|
||||||
chat_prompts: list[ExtraPromptItem] = Field(default_factory=lambda: [])
|
chat_prompts: list[ExtraPromptItem] = Field(default_factory=lambda: [])
|
||||||
|
|
@ -512,6 +522,7 @@ class ExperimentalConfig(ConfigBase):
|
||||||
|
|
||||||
class MaimMessageConfig(ConfigBase):
|
class MaimMessageConfig(ConfigBase):
|
||||||
"""maim_message配置类"""
|
"""maim_message配置类"""
|
||||||
|
|
||||||
ws_server_host: str = "127.0.0.1"
|
ws_server_host: str = "127.0.0.1"
|
||||||
"""旧版基于WS的服务器主机地址"""
|
"""旧版基于WS的服务器主机地址"""
|
||||||
|
|
||||||
|
|
@ -628,6 +639,7 @@ class DreamConfig(ConfigBase):
|
||||||
raise ValueError(f"first_delay_seconds 不能为负数,当前值: {self.first_delay_seconds}")
|
raise ValueError(f"first_delay_seconds 不能为负数,当前值: {self.first_delay_seconds}")
|
||||||
return super().model_post_init(context)
|
return super().model_post_init(context)
|
||||||
|
|
||||||
|
|
||||||
class WebUIConfig(ConfigBase):
|
class WebUIConfig(ConfigBase):
|
||||||
"""WebUI配置类"""
|
"""WebUI配置类"""
|
||||||
|
|
||||||
|
|
@ -655,6 +667,7 @@ class WebUIConfig(ConfigBase):
|
||||||
enable_paragraph_content: bool = False
|
enable_paragraph_content: bool = False
|
||||||
"""是否在知识图谱中加载段落完整内容(需要加载embedding store,会占用额外内存)"""
|
"""是否在知识图谱中加载段落完整内容(需要加载embedding store,会占用额外内存)"""
|
||||||
|
|
||||||
|
|
||||||
class DatabaseConfig(ConfigBase):
|
class DatabaseConfig(ConfigBase):
|
||||||
"""数据库配置类"""
|
"""数据库配置类"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue