feta:优化AI处理流程
This commit is contained in:
@@ -19,7 +19,7 @@ async def log_bot_message(to_wxid: str, content: str, msg_type: str = "text", me
|
||||
"""
|
||||
try:
|
||||
logger.info(f"message_hook: 开始记录机器人消息")
|
||||
|
||||
|
||||
# 动态导入避免循环依赖
|
||||
from plugins.MessageLogger.main import MessageLogger
|
||||
logger.info(f"message_hook: MessageLogger 导入成功")
|
||||
@@ -34,6 +34,37 @@ async def log_bot_message(to_wxid: str, content: str, msg_type: str = "text", me
|
||||
logger.info(f"message_hook: save_bot_message 调用完成")
|
||||
else:
|
||||
logger.warning("MessageLogger 实例未找到,跳过消息记录")
|
||||
|
||||
# 同步写入 AIChat 群聊 history(避免其他插件的机器人回复缺失,导致上下文混乱/工具误触)
|
||||
try:
|
||||
if to_wxid and to_wxid.endswith("@chatroom"):
|
||||
from utils.plugin_manager import PluginManager
|
||||
|
||||
aichat = PluginManager().plugins.get("AIChat")
|
||||
store = getattr(aichat, "store", None) if aichat else None
|
||||
aichat_config = getattr(aichat, "config", None) if aichat else None
|
||||
|
||||
if store and aichat_config and aichat_config.get("history", {}).get("sync_bot_messages", False):
|
||||
bot_nickname = "机器人"
|
||||
bot_wxid = ""
|
||||
try:
|
||||
import tomllib
|
||||
with open("main_config.toml", "rb") as f:
|
||||
main_config = tomllib.load(f)
|
||||
bot_nickname = main_config.get("Bot", {}).get("nickname") or bot_nickname
|
||||
bot_wxid = main_config.get("Bot", {}).get("wxid") or ""
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
await store.add_group_message(
|
||||
to_wxid,
|
||||
bot_nickname,
|
||||
content,
|
||||
role="assistant",
|
||||
sender_wxid=bot_wxid or None,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug(f"message_hook: 同步 AIChat 群聊 history 失败: {e}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"记录机器人消息失败: {e}")
|
||||
@@ -85,4 +116,4 @@ def create_file_message_hook(original_method, msg_type: str):
|
||||
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user