From 4ffcb3065f15a3b88fc6ab70775ac61904f7f323 Mon Sep 17 00:00:00 2001 From: NyaaByte <1500532940@qq.com> Date: Sun, 22 Mar 2026 22:30:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D=E5=90=8C=E6=97=B6=E6=B7=BB=E5=8A=A0=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=EF=BC=8C=E4=BF=9D=E8=AF=81=E6=80=BB=E5=8D=A0?= =?UTF-8?q?=E6=AF=94=E4=B8=8D=E8=B6=85=E8=BF=87=20100%=20(#119=20@J621111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修改提示词同时添加后端校验,保证总占比不超过 100% * fix: 将 ai 返回的占比限制在 [0, 100] --- _conf_schema.json | 6 +++--- .../analyzers/chat_quality_analyzer.py | 18 ++++++++++++++++-- .../retro_futurism/chat_quality_item.html | 14 +------------- .../scrapbook/chat_quality_item.html | 19 ++----------------- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/_conf_schema.json b/_conf_schema.json index b89785b..0c0915a 100644 --- a/_conf_schema.json +++ b/_conf_schema.json @@ -421,7 +421,7 @@ "type": "object", "hint": "金句分析提示词模板,可自定义修改,保留变量 {max_golden_quotes} 和 {messages_text} 写法不要更改,需要写 JSON 块请使用双花括号 {{ ... }} 兼容当前编辑存在的问题。非常推荐根据实际群聊情况进行优化,保留一定提示样本示例供模型参考", "items": { - "golden_quote_v2_prompt": { + "golden_quote_v2_prompt": { "description": "默认金句分析提示词", "type": "text", "editor_mode": true, @@ -440,7 +440,7 @@ "type": "text", "editor_mode": true, "editor_language": "markdown", - "default": "你是一个毒舌且幽默的群聊质量分析师,请生成聊天质量锐评内容。你需要按照下面的格式返回结果。\n\n分析接下来的群聊内容,给出多个维度的分析(3-6个)和汇总内容。\n\n群聊记录:\n{messages_text}\n\n### 返回格式示例:\n\n```json\n{{\n \"title\": \"群聊质量分析报告\",\n \"subtitle\": \"今天的群里发生了什么?\",\n \"dimensions\": [\n {{\n \"name\": \"水群闲聊\",\n \"percentage\": 50.0,\n \"comment\": \"群友们今天也在努力划水呢。\"\n }}\n ],\n \"summary\": \"今天也是元气满满的一天。\"\n}}\n```" + "default": "你是一个毒舌且幽默的群聊质量分析师,请生成聊天质量锐评内容。你需要按照下面的格式返回结果。\n\n分析接下来的群聊内容,给出多个维度的分析(3-6个,所有维度的占比加起来小于等于100%)和汇总内容。\n\n群聊记录:\n{messages_text}\n\n### 返回格式示例:\n\n```json\n{{\n \"title\": \"群聊质量分析报告\",\n \"subtitle\": \"今天的群里发生了什么?\",\n \"dimensions\": [\n {{\n \"name\": \"水群闲聊\",\n \"percentage\": 50.0,\n \"comment\": \"群友们今天也在努力划水呢。\"\n }}\n ],\n \"summary\": \"今天也是元气满满的一天。\"\n}}\n```" } } } @@ -471,4 +471,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/infrastructure/analysis/analyzers/chat_quality_analyzer.py b/src/infrastructure/analysis/analyzers/chat_quality_analyzer.py index 7915c10..7307117 100644 --- a/src/infrastructure/analysis/analyzers/chat_quality_analyzer.py +++ b/src/infrastructure/analysis/analyzers/chat_quality_analyzer.py @@ -91,7 +91,7 @@ class ChatQualityAnalyzer(BaseAnalyzer): ## 任务目标: 1. 将聊天内容划分为 3-6 个不同的维度/类别(如:技术探讨、水群闲聊、就业焦虑、深夜发情等)。 -2. 为每个维度计算一个大致的百分比占位(总和为 100%)。 +2. 为每个维度计算一个大致的百分比占位(总和小于等于 100%)。 3. 为每个维度写一句犀利、幽默、毒舌或温情的点评。 4. 给出一句总结性的全群表现评价。 5. 设定一个本次报告的主题标题和副标题。 @@ -153,12 +153,26 @@ class ChatQualityAnalyzer(BaseAnalyzer): Returns: QualityReview 数据对象 """ + # 控制维度占比总和不超过100% + total_percentage = sum( + max(0.0, min(100.0, float(d.get("percentage", 0)))) + for d in data.get("dimensions", []) + ) + + factor = 1.0 + if total_percentage > 100: + factor = 100.0 / total_percentage + dimensions = [] for d in data.get("dimensions", []): + raw_p = float(d.get("percentage", 0)) + + final_p = round(max(0.0, min(100.0, raw_p)) * factor, 1) + dimensions.append( QualityDimension( name=d.get("name", "未知"), - percentage=float(d.get("percentage", 0)), + percentage=final_p, comment=d.get("comment", ""), ) ) diff --git a/src/infrastructure/reporting/templates/retro_futurism/chat_quality_item.html b/src/infrastructure/reporting/templates/retro_futurism/chat_quality_item.html index c005524..227049e 100644 --- a/src/infrastructure/reporting/templates/retro_futurism/chat_quality_item.html +++ b/src/infrastructure/reporting/templates/retro_futurism/chat_quality_item.html @@ -139,25 +139,13 @@
- {% set total = 0 %} - {% for dim in dimensions %} - {% set total = total + dim.percentage %} - {% endfor %} - - {% set scale = 1 %} - {% if total > 100 %} - {% set scale = 100 / total %} - {% elif total > 0 %} - {% set scale = 100 / total %} - {% endif %} - {% set bg_colors = ['var(--c-accent)', 'var(--c-dec-1)', 'var(--c-dec-3)', 'var(--c-dec-2)', '#FFBA08', '#273C75', '#E07A5F', '#8D99AE'] %} {% set txt_colors = ['#ffffff', '#ffffff', '#000000', '#ffffff', '#000000', '#ffffff', '#000000', '#ffffff'] %} {% for dim in dimensions %} {% if dim.percentage > 0 %}
{{ dim.name }} {{ dim.percentage }}% diff --git a/src/infrastructure/reporting/templates/scrapbook/chat_quality_item.html b/src/infrastructure/reporting/templates/scrapbook/chat_quality_item.html index 77ccc96..ac6645f 100644 --- a/src/infrastructure/reporting/templates/scrapbook/chat_quality_item.html +++ b/src/infrastructure/reporting/templates/scrapbook/chat_quality_item.html @@ -233,21 +233,6 @@
{% set ns = namespace(total=0) %} - {% for dim in dimensions %} - {% set safe_percentage = dim.percentage|float %} - {% if safe_percentage < 0 %} - {% set safe_percentage = 0 %} - {% elif safe_percentage > 100 %} - {% set safe_percentage = 100 %} - {% endif %} - {% set ns.total = ns.total + safe_percentage %} - {% endfor %} - - {% set scale = 1 %} - {% if ns.total > 0 %} - {% set scale = 100 / ns.total %} - {% endif %} - {% set colors = ['#ffb74d', '#ff8a65', '#ba68c8', '#4db6ac', '#4dd0e1', '#64b5f6', '#81c784', '#e57373'] %} {% for dim in dimensions %} {% set safe_percentage = dim.percentage|float %} @@ -258,7 +243,7 @@ {% endif %} {% if safe_percentage > 0 %}
@@ -287,7 +272,7 @@
{{ dim.name }} - {{ '%.1f'|format(safe_percentage * scale) }}% + {{ '%.1f'|format(safe_percentage) }}%
{{ dim.comment }}