优化斗鱼弹幕总结:新增粉丝向弹幕萃取区块并调整提示词语气

This commit is contained in:
liuwei
2026-04-17 11:17:16 +08:00
parent e56c0069cc
commit 5098c191de
2 changed files with 159 additions and 8 deletions

View File

@@ -462,7 +462,8 @@ class DouyuRedisManager:
class DouyuPlugin(MessagePluginInterface):
_DAILY_REPORT_CACHE_VERSION = 3
# 报告结构有新增(粉丝向弹幕萃取区块),提升缓存版本以触发重新生成。
_DAILY_REPORT_CACHE_VERSION = 4
FEATURE_KEY = "DOUYU_MONITOR"
FEATURE_DESCRIPTION = "🎮 斗鱼开播提醒 [订阅斗鱼 房间号, 取消订阅斗鱼 房间号]"
@@ -1538,14 +1539,70 @@ class DouyuPlugin(MessagePluginInterface):
"请输出一段适合放在日报图片上半部分的弹幕总结,要求:\n"
"1. 先用 1 段总述直播氛围与主线。\n"
"2. 再用 5 条要点总结观众关注点、情绪变化、反复出现的梗、节奏变化和额外反馈,每条只写一句。\n"
"3. 语言像运营复盘,简洁自然\n"
"4. 不要写标题,不要写“根据数据”。\n\n"
"3. 另起一行固定写标题:`【粉丝向弹幕萃取】`\n"
"4. 在该标题下输出 4-6 条短句,尽量保留弹幕原话风格(可以保留口头语、玩梗、情绪词)。\n"
"5. 整体语气要像“直播间现场记录”,不要写成运营复盘。\n"
"6. 不要写“根据数据”“建议”“策略”等词。\n\n"
f"主播:{meta.get('nickname') or meta.get('room_name') or meta.get('room_id')}\n"
f"日期:{meta.get('anchor_day', '')}\n"
f"材料:\n{json.dumps(payload, ensure_ascii=False, indent=2)}"
)
return system_prompt, user_prompt
def _build_fans_extract_lines(self, payload: Dict[str, Any], limit: int = 6) -> List[str]:
# 粉丝向萃取强调“可读、像现场弹幕”,优先取代表发言,再补充重复梗与情绪短词。
representative_messages = payload.get("representative_messages", []) or []
repeated_messages = payload.get("repeated_messages", []) or []
merged_templates = payload.get("merged_templates", []) or []
burst_terms = payload.get("burst_terms", []) or []
lines: List[str] = []
seen = set()
def push(text: str) -> None:
value = str(text or "").strip()
if not value:
return
key = value.lower()
if key in seen:
return
seen.add(key)
lines.append(value)
for item in representative_messages[:10]:
nickname = str(item.get("nickname") or "").strip() or "观众"
content = str(item.get("content") or "").strip()
if content:
push(f"{nickname}{content[:56]}")
if len(lines) >= limit:
return lines[:limit]
for item in repeated_messages[:6]:
text = str(item.get("text") or "").strip()
count = int(item.get("count", 0) or 0)
if text:
push(f"复读梗「{text[:36]}」刷了 {count} 次。")
if len(lines) >= limit:
return lines[:limit]
for item in merged_templates[:6]:
text = str(item.get("text") or "").strip()
count = int(item.get("count", 0) or 0)
if text:
push(f"共识弹幕「{text[:36]}」出现 {count} 次。")
if len(lines) >= limit:
return lines[:limit]
for item in burst_terms[:4]:
text = str(item.get("text") or "").strip()
count = int(item.get("count", 0) or 0)
if text:
push(f"情绪短词「{text}」集中出现 {count} 次。")
if len(lines) >= limit:
return lines[:limit]
return lines[:limit]
def _build_fallback_daily_report(self, payload: Dict[str, Any]) -> str:
meta = payload.get("report_meta", {}) or {}
title_name = str(meta.get("nickname") or meta.get("room_name") or meta.get("room_id") or "主播")
@@ -1671,6 +1728,12 @@ class DouyuPlugin(MessagePluginInterface):
lines.append("- 情绪特点:代表性发言里既有对操作和决策的即时反馈,也有大量玩梗、调侃和情绪宣泄。")
if top_terms:
lines.append(f"- 关注焦点:高频词主要落在 {''.join(top_terms[:6])},说明观众注意力相对集中。")
# 在兜底模式下也强制补出“粉丝向弹幕萃取”,避免图片模板出现空区块。
fans_extract_lines = self._build_fans_extract_lines(payload, limit=6)
if fans_extract_lines:
lines.append("【粉丝向弹幕萃取】")
for item in fans_extract_lines:
lines.append(f"- {item}")
return "\n".join(lines).strip()
def _build_operator_summary_text(self, payload: Dict[str, Any]) -> str: