94 lines
3.5 KiB
Python
94 lines
3.5 KiB
Python
"""应用 8:维客线索整理 Prompt 模板。
|
||
|
||
接收 App3(消费分析)和 App6(备注分析)的全部线索,
|
||
整合去重后输出统一维客线索。
|
||
|
||
分类标签限定 6 个枚举值(与 member_retention_clue CHECK 约束一致):
|
||
客户基础、消费习惯、玩法偏好、促销偏好、社交关系、重要反馈。
|
||
|
||
合并规则:
|
||
- 相似线索合并,providers 以逗号分隔
|
||
- 其余线索原文返回
|
||
- 最小改动原则
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
|
||
|
||
def build_prompt(context: dict) -> list[dict]:
|
||
"""构建 App8 维客线索整理 Prompt。
|
||
|
||
Args:
|
||
context: 包含以下字段:
|
||
- site_id: int
|
||
- member_id: int
|
||
- app3_clues: list[dict] — App3 产出的线索列表
|
||
- app6_clues: list[dict] — App6 产出的线索列表
|
||
- app3_generated_at: str | None — App3 线索生成时间
|
||
- app6_generated_at: str | None — App6 线索生成时间
|
||
|
||
Returns:
|
||
消息列表 [{"role": "system", ...}, {"role": "user", ...}]
|
||
"""
|
||
member_id = context["member_id"]
|
||
app3_clues = context.get("app3_clues", [])
|
||
app6_clues = context.get("app6_clues", [])
|
||
app3_generated_at = context.get("app3_generated_at")
|
||
app6_generated_at = context.get("app6_generated_at")
|
||
|
||
system_content = {
|
||
"task": "整合去重来自消费分析和备注分析的维客线索,输出统一线索列表。",
|
||
"app_id": "app8_consolidation",
|
||
"rules": {
|
||
"category_enum": [
|
||
"客户基础", "消费习惯", "玩法偏好",
|
||
"促销偏好", "社交关系", "重要反馈",
|
||
],
|
||
"merge_strategy": (
|
||
"相似线索合并为一条,providers 以逗号分隔(如 '系统,张三');"
|
||
"不相似的线索原文保留,不做修改。最小改动原则。"
|
||
),
|
||
"output_format": {
|
||
"clues": [
|
||
{
|
||
"category": "枚举值(6 选 1)",
|
||
"summary": "一句话摘要",
|
||
"detail": "详细说明",
|
||
"emoji": "表情符号",
|
||
"providers": "提供者(逗号分隔)",
|
||
}
|
||
]
|
||
},
|
||
},
|
||
"input": {
|
||
"app3_clues": {
|
||
"source": "消费数据分析(App3)",
|
||
"generated_at": app3_generated_at,
|
||
"clues": app3_clues,
|
||
},
|
||
"app6_clues": {
|
||
"source": "备注分析(App6)",
|
||
"generated_at": app6_generated_at,
|
||
"clues": app6_clues,
|
||
},
|
||
},
|
||
}
|
||
|
||
user_content = (
|
||
f"请整合会员 {member_id} 的维客线索。\n"
|
||
"输入包含两个来源的线索:App3(消费数据分析)和 App6(备注分析)。\n"
|
||
"规则:\n"
|
||
"1. 相似线索合并为一条,providers 字段以逗号分隔多个提供者\n"
|
||
"2. 不相似的线索原文保留\n"
|
||
"3. category 必须是:客户基础、消费习惯、玩法偏好、促销偏好、社交关系、重要反馈 之一\n"
|
||
"4. 每条线索包含 category、summary、detail、emoji、providers 五个字段\n"
|
||
"5. 最小改动原则,尽量保留原始表述"
|
||
)
|
||
|
||
return [
|
||
{"role": "system", "content": json.dumps(system_content, ensure_ascii=False)},
|
||
{"role": "user", "content": user_content},
|
||
]
|