mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 05:31:52 +00:00
fix: 重构金句分析匹配机制 (#104)
- [修复] 尝试解决金句头像无法显示的问题。通过将 Prompt 输入改为 [user_id] 标识符,实现 100% 准确的身份回填,彻底消除了由于 LLM 微调内容导致的匹配失败。 - [警告] 强制初始化金句提示词,丢弃原本用户可能自定义的金句提示词模板。重命名配置项为 golden_quote_v2_prompt,避免用户更新后旧版本提示词干扰导致 LLM 金句分析功能失效。
This commit is contained in:
+2
-2
@@ -396,12 +396,12 @@
|
||||
"type": "object",
|
||||
"hint": "金句分析提示词模板,可自定义修改,保留变量 {max_golden_quotes} 和 {messages_text} 写法不要更改,需要写 JSON 块请使用双花括号 {{ ... }} 兼容当前编辑存在的问题。非常推荐根据实际群聊情况进行优化,保留一定提示样本示例供模型参考",
|
||||
"items": {
|
||||
"golden_quote_prompt": {
|
||||
"golden_quote_v2_prompt": {
|
||||
"description": "默认金句分析提示词",
|
||||
"type": "text",
|
||||
"editor_mode": true,
|
||||
"editor_language": "markdown",
|
||||
"default": "请从以下群聊记录中挑选出 **{max_golden_quotes}** 句最具冲击力、最令人惊叹的「金句」。\n\n## 金句标准:\n\n- **核心标准**:**逆天的神人发言**,即具备颠覆常识的脑洞、逻辑跳脱的表达或强烈反差感的原创内容\n- **典型特征**:包含某些争议话题元素、夸张类比、反常规结论、一本正经的「胡说八道」或突破语境的清奇思路,并且具备一定的冲击力,让人印象深刻\n\n## 对于每个金句,请提供:\n\n1. **原文内容**(完整保留发言细节)\n2. **发言人昵称**\n3. **选择理由**(具体说明其「逆天」之处,如逻辑颠覆点/脑洞角度/反差感/争议话题元素)\n\n## 严格约束:\n\n- 优先筛选 **逆天指数最高** 的内容:\n - 发情、性压抑话题 > 争议话题 > 元素级 > 颠覆认知级 > 逻辑跳脱级 > 趣味调侃级\n - 剔除单纯玩梗或网络热词堆砌的普通发言\n- 重点标记包含极端类比、反常识论证或无厘头结论的内容,并且包含一定的争议话题元素\n\n## 群聊记录:\n\n{messages_text}\n\n---\n\n### 返回格式示例:\n\n```json\n[\n {{\n \"content\": \"金句原文\",\n \"sender\": \"发言人昵称\",\n \"reason\": \"选择这句话的理由(需明确说明逆天特质)\"\n }}\n]\n```\n\n**注意**:请以纯 JSON 格式返回,不要包含 markdown 代码块标记。"
|
||||
"default": "请从以下群聊记录中挑选出 **{max_golden_quotes}** 句最具冲击力、最令人惊叹的「金句」。\n\n## 金句标准:\n\n- **核心标准**:**逆天的神人发言**,即具备颠覆常识的脑洞、逻辑跳脱的表达或强烈反差感的原创内容\n- **典型特征**:包含某些争议话题元素、夸张类比、反常规结论、一本正经的「胡说八道」或突破语境的清奇思路,并且具备一定的冲击力,让人印象深刻\n\n## 对于每个金句,请提供:\n\n1. **原文内容**(完整保留发言细节)\n2. **发言人用户ID**(必须严格使用消息记录中提供的 [用户ID])\n3. **选择理由**(具体说明其「逆天」之处,如逻辑颠覆点/脑洞角度/反差感/争议话题元素)\n\n## 严格约束:\n\n- 优先筛选 **逆天指数最高** 的内容:\n - 发情、性压抑话题 > 争议话题 > 元素级 > 颠覆认知级 > 逻辑跳脱级 > 趣味调侃级\n - 剔除单纯玩梗或网络热词堆砌的普通发言\n- 重点标记包含极端类比、反常识论证或无厘头结论的内容,并且包含一定的争议话题元素\n- **身份对齐**:返回的 `sender` 字段必须是 `[用户ID]` 格式(例如 `[123456]`)。我们会根据 ID 自动还原昵称和头像。\n\n## 群聊记录格式: [HH:MM] [用户ID]: 消息内容\n\n## 群聊记录:\n\n{messages_text}\n\n---\n\n### 返回格式示例:\n\n```json\n[\n {{\n \"content\": \"金句原文\",\n \"sender\": \"[123456789]\",\n \"reason\": \"选择这句话的理由(需明确说明逆天特质)\"\n }}\n]\n```\n\n**注意**:请以纯 JSON 格式返回,不要包含 markdown 代码块标记。"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ class GoldenQuoteAnalyzer(BaseAnalyzer):
|
||||
if not data:
|
||||
return ""
|
||||
|
||||
# 构建消息文本
|
||||
# 构建消息文本 (用 [user_id] 替代 nickname 以确保回填 100% 准确,避免 Emoji 等干扰)
|
||||
messages_text = "\n".join(
|
||||
[f"[{msg['time']}] {msg['sender']}: {msg['content']}" for msg in data]
|
||||
[f"[{msg['time']}] [{msg['user_id']}]: {msg['content']}" for msg in data]
|
||||
)
|
||||
|
||||
max_golden_quotes = self.get_max_count()
|
||||
@@ -155,17 +155,24 @@ class GoldenQuoteAnalyzer(BaseAnalyzer):
|
||||
logger.info(f"开始从 {len(interesting_messages)} 条圣经消息中提取金句")
|
||||
quotes, usage = await self.analyze(interesting_messages, umo, session_id)
|
||||
|
||||
# 回填 User ID
|
||||
# 建立 ID 到昵称的映射表用于恢复显示
|
||||
id_to_nickname = {}
|
||||
for msg in interesting_messages:
|
||||
uid = str(msg.get("user_id", ""))
|
||||
if uid:
|
||||
id_to_nickname[uid] = msg.get("sender", "")
|
||||
|
||||
# 回填 User ID 并恢复发送者昵称
|
||||
for quote in quotes:
|
||||
for msg in interesting_messages:
|
||||
# 尝试匹配内容和发送者
|
||||
# 注意:LLM 可能会微调内容,这里使用包含匹配或精确匹配
|
||||
if (
|
||||
quote.content in msg["content"]
|
||||
or msg["content"] in quote.content
|
||||
) and quote.sender == msg["sender"]:
|
||||
quote.user_id = str(msg.get("user_id", ""))
|
||||
break
|
||||
# 此时 quote.sender 包含的是 Prompt 中的 [user_id]
|
||||
# 有些 LLM 可能会带上中括号,尝试清理
|
||||
potential_id = quote.sender.strip().strip("[]")
|
||||
|
||||
if potential_id in id_to_nickname:
|
||||
quote.user_id = potential_id
|
||||
quote.sender = id_to_nickname[potential_id]
|
||||
else:
|
||||
logger.warning(f"[金句分析] 无法匹配 User ID: {potential_id},金句将无法显示真实头像。")
|
||||
|
||||
return quotes, usage
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ class ConfigManager:
|
||||
return ""
|
||||
|
||||
def get_golden_quote_analysis_prompt(
|
||||
self, style: str = "golden_quote_prompt"
|
||||
self, style: str = "golden_quote_v2_prompt"
|
||||
) -> str:
|
||||
"""获取金句分析提示词模板"""
|
||||
prompts_config = self._get_group("prompts").get(
|
||||
@@ -298,7 +298,7 @@ class ConfigManager:
|
||||
prompts = self._ensure_group("prompts")
|
||||
if "golden_quote_analysis_prompts" not in prompts:
|
||||
prompts["golden_quote_analysis_prompts"] = {}
|
||||
prompts["golden_quote_analysis_prompts"]["golden_quote_prompt"] = prompt
|
||||
prompts["golden_quote_analysis_prompts"]["golden_quote_v2_prompt"] = prompt
|
||||
self.config.save_config()
|
||||
|
||||
def set_output_format(self, format_type: str):
|
||||
|
||||
Reference in New Issue
Block a user