feat(ai_auto_response): handle image follow-up more safely

This commit is contained in:
liuwei
2026-04-09 10:06:39 +08:00
parent 3900d38952
commit cc65378544
3 changed files with 123 additions and 14 deletions

View File

@@ -51,6 +51,9 @@ class ContextBuilder:
"group_profile_prompt": self._build_group_profile_prompt(group_profile or {}),
"quote_prompt": self._build_quote_prompt(quote_context or {}),
"image_prompt": self._build_image_prompt(image_context or {}),
"image_safety_prompt": self._build_image_safety_prompt(
(quote_context or {}).get("image_safety") or {}
),
"current_message": f"{sender_name}: {content}",
}
@@ -323,3 +326,18 @@ class ContextBuilder:
f"图片说明:{image_context.get('hint', '')}" if image_context.get("hint") else "",
]
return "\n".join([line for line in lines if line])
@staticmethod
def _build_image_safety_prompt(image_safety: Dict) -> str:
if not image_safety or not image_safety.get("suspected"):
return ""
if image_safety.get("has_visual_context"):
return "当前发言疑似是在评论图片,但本次已附带图片上下文,可以基于图片谨慎理解。"
reason = str(image_safety.get("reason", "") or "").strip()
lines = [
"当前发言疑似是在评论图片,但你这次没有看到图片本身。",
f"原因:{reason}" if reason else "",
"不要假装看过图,不要直接评价画面细节、人物状态、构图、文字内容或颜色元素。",
"如果要回,只能轻微承认信息不足,或请对方引用图片/补一句文字说明,再继续。",
]
return "\n".join([line for line in lines if line])