feat(context): 增强s4u跨上下文模式并重构API

在跨上下文功能中为s4u模式引入`s4u_ignore_whitelist`配置项。当启用时,除了白名单中配置的聊天记录外,还会自动获取目标用户与Bot的私聊记录,以构建更全面的用户画像。

主要变更:
- 在 `ContextGroup` 配置中添加 `s4u_ignore_whitelist` 字段。
- 重构 `cross_context_api`,将 `get_context_groups` 更改为 `get_context_group`,使其返回完整的 `ContextGroup` 对象而非仅ID列表,以便于访问新配置。
- 调整 `build_cross_context_s4u` 函数以处理新逻辑,包括获取私聊记录和避免重复处理。
- 更新了配置文件模板以包含新选项的说明和示例。
This commit is contained in:
minecraft1024a
2025-10-11 19:19:52 +08:00
parent 67ab97edef
commit 419d1a483a
4 changed files with 95 additions and 44 deletions

View File

@@ -1047,8 +1047,8 @@ class Prompt:
from src.plugin_system.apis import cross_context_api
other_chat_raw_ids = await cross_context_api.get_context_groups(chat_id)
if not other_chat_raw_ids:
context_group = await cross_context_api.get_context_group(chat_id)
if not context_group:
return ""
chat_stream = await get_chat_manager().get_stream(chat_id)
@@ -1056,9 +1056,18 @@ class Prompt:
return ""
if prompt_mode == "normal":
return await cross_context_api.build_cross_context_normal(chat_stream, other_chat_raw_ids)
current_chat_raw_id = (
chat_stream.group_info.group_id if chat_stream.group_info else chat_stream.user_info.user_id
)
current_type = "group" if chat_stream.group_info else "private"
other_chat_infos = [
chat_info
for chat_info in context_group.chat_ids
if chat_info[:2] != [current_type, str(current_chat_raw_id)]
]
return await cross_context_api.build_cross_context_normal(chat_stream, other_chat_infos)
elif prompt_mode == "s4u":
return await cross_context_api.build_cross_context_s4u(chat_stream, other_chat_raw_ids, target_user_info)
return await cross_context_api.build_cross_context_s4u(chat_stream, context_group, target_user_info)
return ""