fix: 改进今日要点摘要,要求包含具体数字和事项主题
- 规则摘要: 将进行中案卡按场景归类,不再只看 red/orange - AI prompt: 要求引用具体案卡标题和数字,禁止空泛表述 - 兜底文案: 无案卡时不再提及已移除的健康度 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2410,6 +2410,10 @@ def dashboard_today(authorization: str | None = Header(default=None)):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
# 场景中文映射(用于摘要)
|
||||||
|
SCENE_LABELS_MAP = {"legal": "法务", "decision": "决策", "life": "生活", "emotion": "情绪"}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/dashboard/summary")
|
@app.get("/dashboard/summary")
|
||||||
def dashboard_summary(authorization: str | None = Header(default=None)):
|
def dashboard_summary(authorization: str | None = Header(default=None)):
|
||||||
"""老板台执行摘要:AI 用一句话总结当前状态和建议行动。
|
"""老板台执行摘要:AI 用一句话总结当前状态和建议行动。
|
||||||
@@ -2443,20 +2447,31 @@ def dashboard_summary(authorization: str | None = Header(default=None)):
|
|||||||
|
|
||||||
red_count = sum(1 for m in open_matters if m["risk_level"] == "red")
|
red_count = sum(1 for m in open_matters if m["risk_level"] == "red")
|
||||||
orange_count = sum(1 for m in open_matters if m["risk_level"] == "orange")
|
orange_count = sum(1 for m in open_matters if m["risk_level"] == "orange")
|
||||||
|
open_count = len(open_matters)
|
||||||
|
|
||||||
# 规则摘要(兜底)
|
# 规则摘要(兜底)
|
||||||
parts = []
|
parts = []
|
||||||
if red_count > 0:
|
if red_count > 0:
|
||||||
parts.append(f"有 {red_count} 项高风险事项需立即处理")
|
parts.append(f"{red_count} 项高风险需立即处理")
|
||||||
if orange_count > 0:
|
if orange_count > 0:
|
||||||
parts.append(f"{orange_count} 项中风险事项需关注")
|
parts.append(f"{orange_count} 项中风险需关注")
|
||||||
if pending_count > 0:
|
if pending_count > 0:
|
||||||
parts.append(f"{pending_count} 个事项待你确认")
|
parts.append(f"{pending_count} 个待确认")
|
||||||
if reply_count > 0:
|
if reply_count > 0:
|
||||||
parts.append(f"{reply_count} 条专家回复待查看")
|
parts.append(f"{reply_count} 条专家回复待查看")
|
||||||
|
# 有进行中的案卡但无风险标记
|
||||||
|
ongoing = open_count - red_count - orange_count
|
||||||
|
if ongoing > 0 and not parts:
|
||||||
|
# 按场景归类
|
||||||
|
scene_counts: dict[str, int] = {}
|
||||||
|
for m in open_matters:
|
||||||
|
sc = SCENE_LABELS_MAP.get(m["scene"], m["scene"])
|
||||||
|
scene_counts[sc] = scene_counts.get(sc, 0) + 1
|
||||||
|
scene_desc = "、".join(f"{k}{v}项" for k, v in scene_counts.items())
|
||||||
|
parts.append(f"{ongoing} 项{scene_desc}进行中")
|
||||||
if not parts:
|
if not parts:
|
||||||
rule_summary = "当前无待办事项,经营状况良好。可主动发起咨询或查看经营健康度。"
|
rule_summary = "当前无待办事项,经营状况良好。"
|
||||||
rule_action = "浏览智囊或查看事项看板"
|
rule_action = "可主动发起咨询或浏览智囊"
|
||||||
else:
|
else:
|
||||||
rule_summary = "、".join(parts) + "。"
|
rule_summary = "、".join(parts) + "。"
|
||||||
if red_count > 0:
|
if red_count > 0:
|
||||||
@@ -2465,6 +2480,10 @@ def dashboard_summary(authorization: str | None = Header(default=None)):
|
|||||||
rule_action = "建议先确认待办事项"
|
rule_action = "建议先确认待办事项"
|
||||||
elif reply_count > 0:
|
elif reply_count > 0:
|
||||||
rule_action = "建议查看专家回复"
|
rule_action = "建议查看专家回复"
|
||||||
|
elif ongoing > 0:
|
||||||
|
# 取最近的案卡标题作为建议
|
||||||
|
latest = open_matters[0]["title"] if open_matters else ""
|
||||||
|
rule_action = f"继续跟进「{latest[:15]}」" if latest else "建议跟进进行中的事项"
|
||||||
else:
|
else:
|
||||||
rule_action = "建议关注中风险事项"
|
rule_action = "建议关注中风险事项"
|
||||||
|
|
||||||
@@ -2472,13 +2491,16 @@ def dashboard_summary(authorization: str | None = Header(default=None)):
|
|||||||
try:
|
try:
|
||||||
if kimi and open_matters:
|
if kimi and open_matters:
|
||||||
matter_desc = "\n".join(
|
matter_desc = "\n".join(
|
||||||
f"- {m['title']}(风险:{m['risk_level']},场景:{m['scene']},状态:{m['status']})"
|
f"- {m['title']}(场景:{SCENE_LABELS_MAP.get(m['scene'], m['scene'])},状态:{m['status']})"
|
||||||
for m in open_matters[:5]
|
for m in open_matters[:5]
|
||||||
)
|
)
|
||||||
prompt = (
|
prompt = (
|
||||||
f"你是中小企业老板的AI助手。请根据以下数据,用一句话(不超过50字)总结当前经营状态,"
|
f"你是中小企业老板的AI助手。请根据以下待办事项数据,生成今日要点摘要。\n"
|
||||||
f"并给出一个最优先的行动建议(不超过20字)。\n\n"
|
f"要求:\n"
|
||||||
f"待办事项:\n{matter_desc}\n"
|
f"1. summary:一句话总结,必须包含具体数字和事项主题,不超过60字\n"
|
||||||
|
f"2. action:最优先的行动建议,必须引用具体事项标题,不超过25字\n"
|
||||||
|
f"3. 不要用'经营状态稳定'等空泛表述,要基于实际数据\n\n"
|
||||||
|
f"待办事项(共{open_count}项):\n{matter_desc}\n"
|
||||||
f"待确认:{pending_count}个,专家回复:{reply_count}条\n\n"
|
f"待确认:{pending_count}个,专家回复:{reply_count}条\n\n"
|
||||||
f"返回 JSON 格式:{{\"summary\": \"...\", \"action\": \"...\"}}"
|
f"返回 JSON 格式:{{\"summary\": \"...\", \"action\": \"...\"}}"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user