feat(cross_context): 实现按互通组名称获取聊天记录

新增 `get_chat_history_by_group_name` API,允许插件按名称获取指定互通组的聊天记录。此功能增强了插件的上下文感知能力,使其能够利用跨群聊的对话历史。

主要变更:
- 在 `cross_context_api.py` 中添加了 `get_chat_history_by_group_name` 函数。
- Maizone 插件现在利用此 API 来获取跨群聊的上下文,以生成更相关的说说内容。
- 调整了配置文件模板,以反映新的互通组配置方式。
This commit is contained in:
minecraft1024a
2025-09-05 19:51:33 +08:00
committed by Windpicker-owo
parent 156662014b
commit c6e9d572a5
3 changed files with 76 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ from src.common.logger import get_logger
import imghdr
import asyncio
from src.plugin_system.apis import llm_api, config_api, generator_api
from src.plugin_system.apis.cross_context_api import get_chat_history_by_group_name
from src.chat.message_receive.chat_stream import get_chat_manager
from maim_message import UserInfo
from src.llm_models.utils_model import LLMRequest
@@ -87,6 +88,11 @@ class ContentService:
if context:
prompt += f"\n作为参考,这里有一些最近的聊天记录:\n---\n{context}\n---"
# 添加跨群聊上下文
cross_context = await get_chat_history_by_group_name("maizone_context_group")
if cross_context and "找不到名为" not in cross_context:
prompt += f"\n\n---跨群聊参考---\n{cross_context}\n---"
# 添加历史记录以避免重复
prompt += "\n\n---历史说说记录---\n"
history_block = await get_send_history(qq_account)
@@ -232,7 +238,7 @@ class ContentService:
for i in range(3): # 重试3次
try:
async with aiohttp.ClientSession() as session:
async with session.get(image_url, timeout=30) as resp:
async with session.get(image_url, timeout=aiohttp.ClientTimeout(total=30)) as resp:
if resp.status != 200:
logger.error(f"下载图片失败: {image_url}, status: {resp.status}")
await asyncio.sleep(2)