优化引用上下文质量并修复无效引用噪声

变更项:

1. 扩展引用发送者解析字段,新增 fromusr/fromnickname/sourceusername/sourcedisplayname 等兼容项。

2. 增加引用质量门控:发送者、标题、正文均缺失时直接丢弃 quote_context,避免污染 LLM。

3. 构建引用补充时不再输出“被引用发送者:未知成员”等低价值字段。

4. 增加兜底策略:仅剩引用类型且无正文标题时不输出引用补充。
This commit is contained in:
liuwei
2026-04-16 11:12:16 +08:00
parent b4b3fa92e0
commit a68d6d5e6c
2 changed files with 67 additions and 7 deletions

View File

@@ -401,18 +401,22 @@ class ContextBuilder:
if not quote_context:
return ""
quote_type = quote_context.get("quote_type_label", "引用消息")
quote_sender = quote_context.get("quote_sender_name", "") or "未知成员"
quote_sender = (quote_context.get("quote_sender_name", "") or "").strip()
quote_body = quote_context.get("quote_body", "") or ""
title = quote_context.get("title", "") or ""
lines = [
f"用户这次是在引用消息后发言。",
f"引用类型:{quote_type}",
f"被引用发送者:{quote_sender}",
f"被引用发送者:{quote_sender}" if quote_sender and quote_sender != "未知成员" else "",
f"图片附件:已附带原图" if quote_context.get("has_image_attachment") else "",
f"引用标题:{title}" if title else "",
f"被引用内容:{quote_body}" if quote_body else "",
]
return "\n".join([line for line in lines if line])
payload = [line for line in lines if line]
# 兜底:如果最终只剩“引用类型”,没有可用内容,就不输出引用补充
if len(payload) <= 2 and not quote_body and not title:
return ""
return "\n".join(payload)
@staticmethod
def _build_image_prompt(image_context: Dict) -> str: