优化日志和回复逻辑
- 改进 VLM prompt,明确说明微信左右消息布局判断 is_self - 添加详细调试日志,追踪回复判断过程 - 改进 should_reply 逻辑,添加 sender/content 日志
This commit is contained in:
@@ -51,16 +51,28 @@ class MessageProcessor:
|
||||
|
||||
def should_reply(self, chat_snapshot: ChatSnapshot) -> bool:
|
||||
"""判断是否需要回复"""
|
||||
if not chat_snapshot.has_new:
|
||||
return False
|
||||
|
||||
# 检查是否是自己的消息
|
||||
# 检查是否有消息
|
||||
messages = chat_snapshot.messages
|
||||
if not messages:
|
||||
logger.debug("没有消息,不回复")
|
||||
return False
|
||||
|
||||
# 检查最后一条消息
|
||||
last_msg = messages[-1]
|
||||
if last_msg.get("is_self"):
|
||||
sender = last_msg.get("sender", "")
|
||||
content = last_msg.get("content", "")
|
||||
is_self = last_msg.get("is_self", False)
|
||||
|
||||
logger.debug(f"最后一条消息: sender={sender}, is_self={is_self}, content={content[:30]}")
|
||||
|
||||
# 如果是自己发的消息,不回复
|
||||
if is_self:
|
||||
logger.debug("自己发的消息,不回复")
|
||||
return False
|
||||
|
||||
# 检查是否有新消息(未读标记)
|
||||
if not chat_snapshot.has_new:
|
||||
logger.debug("没有新消息,不回复")
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -267,10 +279,16 @@ class WeChatAgent:
|
||||
|
||||
# 判断是否需要回复
|
||||
if self.processor.should_reply(snapshot):
|
||||
logger.info(f"需要回复,生成回复内容...")
|
||||
reply = self.processor.generate_reply(snapshot)
|
||||
if reply:
|
||||
logger.info(f"发送回复: {reply[:50]}...")
|
||||
result = self.send_reply(reply)
|
||||
self._emit("on_reply", result)
|
||||
else:
|
||||
logger.warning("生成回复为空")
|
||||
else:
|
||||
logger.debug("不需要回复(已读消息或自己发送)")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"轮询处理异常: {e}")
|
||||
|
||||
Reference in New Issue
Block a user