refactor(cross_context): 重构S4U上下文检索逻辑并更新配置
将S4U(Search for User)上下文检索模式从依赖于共享组(ContextGroup)的配置中解耦,改为使用独立的全局配置。这使得S4U模式的管理更加清晰和灵活。 主要变更: - **配置模型更新**: 在`CrossContextConfig`中移除了与S4U相关的字段(如`s4u_ignore_whitelist`),并添加了新的S4U专用配置项,包括`s4u_mode`, `s4u_limit`, `s4u_stream_limit`, `s4u_whitelist_chats`, 和 `s4u_blacklist_chats`。 - **S4U逻辑重构**: `build_cross_context_s4u`函数不再接收`context_group`参数,而是直接读取全局的S4U配置来检索用户在白名单或黑名单聊天中的消息。 - **简化调用**: `Prompt.get_cross_context_prompt`中的调用逻辑被简化,以适应新的函数签名。 - **文档与模板更新**: 更新了`bot_config_template.toml`配置文件模板,以反映新的S4U配置结构,并提供了更清晰的注释说明。 此次重构将Normal模式(群组共享)和S4U模式(用户中心)的配置和实现完全分离,提高了代码的可维护性和配置的直观性。
This commit is contained in:
@@ -643,11 +643,7 @@ class ContextGroup(ValidatedConfigBase):
|
||||
)
|
||||
default_limit: int = Field(
|
||||
default=5,
|
||||
description="在'blacklist'模式下,对于未明确指定数量的聊天,默认获取的消息条数。也用于s4u_ignore_whitelist开启时获取私聊消息的数量。",
|
||||
)
|
||||
s4u_ignore_whitelist: bool = Field(
|
||||
default=False,
|
||||
description="在s4u模式下,是否无视白名单,获取目标用户与Bot的所有私聊消息,以构建更完整的用户画像。",
|
||||
description="在'blacklist'模式下,对于未明确指定数量的聊天,默认获取的消息条数。",
|
||||
)
|
||||
chat_ids: list[list[str]] = Field(
|
||||
...,
|
||||
@@ -655,12 +651,43 @@ class ContextGroup(ValidatedConfigBase):
|
||||
)
|
||||
|
||||
|
||||
class MaizoneContextGroup(ValidatedConfigBase):
|
||||
"""QQ空间专用互通组配置"""
|
||||
|
||||
name: str = Field(..., description="QQ空间互通组的名称")
|
||||
chat_ids: list[list[str]] = Field(
|
||||
...,
|
||||
description='定义组内成员的列表。格式为 [["type", "id"]]。type为"group"或"private",id为群号或用户ID。',
|
||||
)
|
||||
|
||||
|
||||
class CrossContextConfig(ValidatedConfigBase):
|
||||
"""跨群聊上下文共享配置"""
|
||||
|
||||
enable: bool = Field(default=False, description="是否启用跨群聊上下文共享功能")
|
||||
|
||||
# --- Normal模式: 共享组配置 ---
|
||||
groups: list[ContextGroup] = Field(default_factory=list, description="上下文共享组列表")
|
||||
|
||||
# --- S4U模式: 用户中心上下文检索 ---
|
||||
s4u_mode: Literal["whitelist", "blacklist"] = Field(
|
||||
default="whitelist",
|
||||
description="S4U模式的白名单/黑名单模式",
|
||||
)
|
||||
s4u_limit: int = Field(default=5, description="S4U模式下,每个聊天获取的消息条数")
|
||||
s4u_stream_limit: int = Field(default=3, description="S4U模式下,最多检索多少个不同的聊天流")
|
||||
s4u_whitelist_chats: list[str] = Field(
|
||||
default_factory=list,
|
||||
description='S4U模式的白名单列表。格式: ["platform:type:id", ...]',
|
||||
)
|
||||
s4u_blacklist_chats: list[str] = Field(
|
||||
default_factory=list,
|
||||
description='S4U模式的黑名单列表。格式: ["platform:type:id", ...]',
|
||||
)
|
||||
|
||||
# --- QQ空间专用互通组 ---
|
||||
maizone_context_group: list[MaizoneContextGroup] = Field(default_factory=list, description="QQ空间专用互通组列表")
|
||||
|
||||
|
||||
class CommandConfig(ValidatedConfigBase):
|
||||
"""命令系统配置类"""
|
||||
|
||||
Reference in New Issue
Block a user