优化日志和回复逻辑
- 改进 VLM prompt,明确说明微信左右消息布局判断 is_self - 添加详细调试日志,追踪回复判断过程 - 改进 should_reply 逻辑,添加 sender/content 日志
This commit is contained in:
BIN
src/core/__pycache__/engine.cpython-311.pyc
Normal file
BIN
src/core/__pycache__/engine.cpython-311.pyc
Normal file
Binary file not shown.
@@ -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}")
|
||||
|
||||
Binary file not shown.
@@ -283,7 +283,7 @@ class BailianVLMClient:
|
||||
- current_chat: 当前聊天对象名称
|
||||
- has_new_message: 是否有新消息
|
||||
- messages: 消息列表,每条消息包含:
|
||||
- sender: 发送者
|
||||
- sender: 发送者昵称
|
||||
- content: 消息内容
|
||||
- time: 时间
|
||||
- is_self: 是否是自己发送的
|
||||
@@ -295,19 +295,29 @@ class BailianVLMClient:
|
||||
print(f"{msg['sender']}: {msg['content']}")
|
||||
"""
|
||||
prompt = """请分析这个微信聊天截图,返回严格的 JSON 格式,不要包含其他内容:
|
||||
|
||||
关键识别规则:
|
||||
1. 微信消息分为左右两侧:自己在右侧,对方在左侧
|
||||
2. 右侧消息是"我"发送的,is_self=true
|
||||
3. 左侧消息是对方发送的,is_self=false
|
||||
4. 发送者(sender)应该是具体的个人昵称,不是群名或聊天标题
|
||||
5. current_chat 是聊天窗口顶部的标题,如"Anna司梦 米果妈"
|
||||
6. has_new_message 根据右上角是否有红色未读标记判断
|
||||
|
||||
返回 JSON:
|
||||
{
|
||||
"current_chat": "当前聊天对象名称(如果是群聊,返回群名)",
|
||||
"has_new_message": true或false(根据是否有未读标记判断),
|
||||
"current_chat": "聊天窗口标题(顶部标题栏的文字)",
|
||||
"has_new_message": true或false(右上角红色标记),
|
||||
"messages": [
|
||||
{
|
||||
"sender": "发送者昵称",
|
||||
"content": "消息内容(图片用[图片]表示,语音用[语音]表示,视频用[视频]表示,文件用[文件]表示)",
|
||||
"time": "时间字符串,如10:30",
|
||||
"is_self": true或false(是否是自己发送的消息)
|
||||
"sender": "发送者昵称(具体人名,不是聊天名)",
|
||||
"content": "消息内容",
|
||||
"time": "时间如10:30",
|
||||
"is_self": true(右侧消息,我在右侧)或false(左侧消息,对方)
|
||||
}
|
||||
]
|
||||
}
|
||||
只返回 JSON,不要其他文字。"""
|
||||
只返回 JSON,不要任何解释文字。"""
|
||||
|
||||
result = self.analyze_image(screenshot_path, prompt)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user