reply set 数据模型化准备
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
# 组件类型枚举
|
# 组件类型枚举
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
- [x] 随时注册
|
- [x] 随时注册
|
||||||
- [ ] <del>删除event</del>
|
- [ ] <del>删除event</del>
|
||||||
- [ ] 必要性?
|
- [ ] 必要性?
|
||||||
- [ ] 能够更改prompt
|
- [x] 能够更改prompt
|
||||||
- [ ] 能够更改llm_response
|
- [x] 能够更改llm_response
|
||||||
- [ ] 能够更改message
|
- [x] 能够更改message
|
||||||
Reference in New Issue
Block a user