reply set 数据模型化准备

This commit is contained in:
UnCLAS-Prommer
2025-09-08 00:34:06 +08:00
parent 08e1187452
commit ac2936d5fc
6 changed files with 51 additions and 5 deletions

View File

@@ -339,7 +339,7 @@ def process_llm_response(text: str, enable_splitter: bool = True, enable_chinese
else: else:
split_sentences = [cleaned_text] split_sentences = [cleaned_text]
sentences = [] sentences: List[str] = []
for sentence in split_sentences: for sentence in split_sentences:
if global_config.chinese_typo.enable and enable_chinese_typo: if global_config.chinese_typo.enable and enable_chinese_typo:
typoed_text, typo_corrections = typo_generator.create_typo_sentence(sentence) typoed_text, typo_corrections = typo_generator.create_typo_sentence(sentence)

View File

@@ -1,5 +1,6 @@
from typing import Optional, TYPE_CHECKING from typing import Optional, TYPE_CHECKING, List, Tuple, Union
from dataclasses import dataclass, field from dataclasses import dataclass, field
from enum import Enum
from . import BaseDataModel from . import BaseDataModel
@@ -34,3 +35,43 @@ class MessageAndActionModel(BaseDataModel):
display_message=message.display_message, display_message=message.display_message,
chat_info_platform=message.chat_info.platform, chat_info_platform=message.chat_info.platform,
) )
class ReplyContentType(Enum):
TEXT = "text"
IMAGE = "image"
VOICE = "voice"
HYBRID = "hybrid" # 混合类型,包含多种内容
@dataclass
class ReplySetModel(BaseDataModel):
"""
回复集数据模型,用于多种回复类型的返回
"""
reply_set_data: List[Tuple[ReplyContentType | str, Union[str, "ReplySetModel"]]] = field(default_factory=list)
def add_text_content(self, text: str):
"""添加文本内容"""
self.reply_set_data.append((ReplyContentType.TEXT, text))
def add_image_content(self, image_base64: str):
"""添加图片内容base64编码的图片数据"""
self.reply_set_data.append((ReplyContentType.IMAGE, image_base64))
def add_voice_content(self, voice_base64: str):
"""添加语音内容base64编码的音频数据"""
self.reply_set_data.append((ReplyContentType.VOICE, voice_base64))
def add_hybrid_content(self, hybrid_content: "ReplySetModel"):
"""
添加混合型内容,可以包含多种类型的内容
实际解析时只关注最外层,没有递归嵌套处理
"""
self.reply_set_data.append((ReplyContentType.HYBRID, hybrid_content))
def add_custom_content(self, content_type: str, content: str):
"""添加自定义类型的内容"""
self.reply_set_data.append((content_type, content))

View File

@@ -26,6 +26,7 @@ from .base import (
MaiMessages, MaiMessages,
ToolParamType, ToolParamType,
CustomEventHandlerResult, CustomEventHandlerResult,
ReplyContentType,
) )
# 导入工具模块 # 导入工具模块
@@ -100,6 +101,7 @@ __all__ = [
"EventHandlerInfo", "EventHandlerInfo",
"EventType", "EventType",
"ToolParamType", "ToolParamType",
"ReplyContentType",
# 消息 # 消息
"MaiMessages", "MaiMessages",
"CustomEventHandlerResult", "CustomEventHandlerResult",

View File

@@ -24,6 +24,7 @@ from .component_types import (
MaiMessages, MaiMessages,
ToolParamType, ToolParamType,
CustomEventHandlerResult, CustomEventHandlerResult,
ReplyContentType,
) )
from .config_types import ConfigField from .config_types import ConfigField
@@ -48,4 +49,5 @@ __all__ = [
"MaiMessages", "MaiMessages",
"ToolParamType", "ToolParamType",
"CustomEventHandlerResult", "CustomEventHandlerResult",
"ReplyContentType",
] ]

View File

@@ -7,6 +7,7 @@ from maim_message import Seg
from src.llm_models.payload_content.tool_option import ToolParamType as ToolParamType from src.llm_models.payload_content.tool_option import ToolParamType as ToolParamType
from src.llm_models.payload_content.tool_option import ToolCall as ToolCall from src.llm_models.payload_content.tool_option import ToolCall as ToolCall
from src.common.data_models.message_data_model import ReplyContentType as ReplyContentType
# 组件类型枚举 # 组件类型枚举

View File

@@ -8,6 +8,6 @@
- [x] 随时注册 - [x] 随时注册
- [ ] <del>删除event</del> - [ ] <del>删除event</del>
- [ ] 必要性? - [ ] 必要性?
- [ ] 能够更改prompt - [x] 能够更改prompt
- [ ] 能够更改llm_response - [x] 能够更改llm_response
- [ ] 能够更改message - [x] 能够更改message