修复:改进VLM未读判断 + 修复callback显示逻辑
1. VLM prompt: has_new_message 改为检查左侧边栏红点,而非右上角 2. engine.py: callback 显示最新消息,清晰标注 has_new 3. main.py: on_message 回调更新以显示 has_new 状态
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -275,8 +275,19 @@ class WeChatAgent:
|
|||||||
has_new=has_new
|
has_new=has_new
|
||||||
)
|
)
|
||||||
|
|
||||||
# 触发消息回调
|
# 详细日志:打印所有消息(按VLM返回顺序)
|
||||||
self._emit("on_message", snapshot)
|
logger.debug(f"消息列表(共{len(messages)}条,新消息在前):")
|
||||||
|
for i, msg in enumerate(messages[:5]):
|
||||||
|
logger.debug(f" [{i}] sender={msg.get('sender')}, is_self={msg.get('is_self')}, time={msg.get('time')}, content={msg.get('content', '')[:30]}")
|
||||||
|
|
||||||
|
# 触发消息回调(传入最新消息用于显示)
|
||||||
|
latest_msg = messages[0] if messages else {}
|
||||||
|
self._emit("on_message", {
|
||||||
|
"chat_name": chat_name,
|
||||||
|
"latest_message": latest_msg,
|
||||||
|
"has_new": has_new,
|
||||||
|
"all_messages": messages
|
||||||
|
})
|
||||||
|
|
||||||
# 判断是否需要回复
|
# 判断是否需要回复
|
||||||
if self.processor.should_reply(snapshot):
|
if self.processor.should_reply(snapshot):
|
||||||
@@ -289,7 +300,7 @@ class WeChatAgent:
|
|||||||
else:
|
else:
|
||||||
logger.warning("生成回复为空")
|
logger.warning("生成回复为空")
|
||||||
else:
|
else:
|
||||||
logger.debug("不需要回复(已读消息或自己发送)")
|
logger.debug("不需要回复")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"轮询处理异常: {e}")
|
logger.error(f"轮询处理异常: {e}")
|
||||||
|
|||||||
10
src/main.py
10
src/main.py
@@ -121,8 +121,14 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# 注册回调
|
# 注册回调
|
||||||
def on_message(snapshot):
|
def on_message(data):
|
||||||
logger.info(f"收到消息 [{snapshot.chat_name}]: {snapshot.messages[-1] if snapshot.messages else 'N/A'}")
|
chat_name = data.get("chat_name", "")
|
||||||
|
latest = data.get("latest_message", {})
|
||||||
|
has_new = data.get("has_new", False)
|
||||||
|
sender = latest.get("sender", "")
|
||||||
|
content = latest.get("content", "")
|
||||||
|
is_self = latest.get("is_self", False)
|
||||||
|
logger.info(f"收到消息 [{chat_name}]: sender={sender}, is_self={is_self}, has_new={has_new}, content={content}")
|
||||||
|
|
||||||
def on_reply(result):
|
def on_reply(result):
|
||||||
if result.success:
|
if result.success:
|
||||||
|
|||||||
Binary file not shown.
@@ -301,16 +301,20 @@ class BailianVLMClient:
|
|||||||
2. is_self 的判断只看消息位置(右侧=true,左侧=false),与 sender 名字无关
|
2. is_self 的判断只看消息位置(右侧=true,左侧=false),与 sender 名字无关
|
||||||
3. 右侧消息的 sender 应该是"我",左侧消息的 sender 是对方昵称
|
3. 右侧消息的 sender 应该是"我",左侧消息的 sender 是对方昵称
|
||||||
4. current_chat 是聊天窗口顶部的标题,如"尾巴~"
|
4. current_chat 是聊天窗口顶部的标题,如"尾巴~"
|
||||||
5. 重点:has_new_message 取决于右上角是否有红色圆点/数字标记
|
|
||||||
6. 如果当前聊天窗口有未读标记(红点),has_new_message 必须为 true
|
【has_new_message 判断方法】:
|
||||||
|
- 检查聊天列表区域(左侧边栏),看"尾巴~"这一行旁边是否有红色圆点/数字
|
||||||
|
- 如果有未读标记(红点/红数字),has_new_message 必须为 true
|
||||||
|
- 如果没有未读标记,has_new_message 为 false
|
||||||
|
- 注意:即使当前正在查看这个聊天,如果没有点击进去消除红点,仍然算未读
|
||||||
|
|
||||||
返回 JSON:
|
返回 JSON:
|
||||||
{
|
{
|
||||||
"current_chat": "聊天窗口标题(顶部标题栏)",
|
"current_chat": "聊天窗口标题(顶部标题栏)",
|
||||||
"has_new_message": true或false(重点:看右上角红色标记),
|
"has_new_message": true或false(重点:检查左侧边栏该聊天行是否有红点/红数字未读标记),
|
||||||
"messages": [
|
"messages": [
|
||||||
{
|
{
|
||||||
"sender": "发送者昵称",
|
"sender": "发送者昵称(右侧填\"我\",左侧填对方昵称)",
|
||||||
"content": "消息内容",
|
"content": "消息内容",
|
||||||
"time": "时间",
|
"time": "时间",
|
||||||
"is_self": true(右侧气泡=我发的)或false(左侧气泡=对方发的)
|
"is_self": true(右侧气泡=我发的)或false(左侧气泡=对方发的)
|
||||||
|
|||||||
Reference in New Issue
Block a user