refactor: merge reply suggestions into single AI request
- Summary prompt now includes can_reply + reply_suggestions fields - Removed separate generate_reply_suggestions function and REPLY_PROMPT - tg_bot reads reply suggestions from cached summary_data - AI Reply button conditionally hidden based on can_reply
This commit is contained in:
@@ -15,10 +15,21 @@ SYSTEM_PROMPT = """你是一个邮件摘要助手。请分析邮件内容并以
|
||||
"priority": "high/medium/low",
|
||||
"action_required": true/false,
|
||||
"action_items": ["待办事项1", "待办事项2"],
|
||||
"key_points": ["关键要点1", "关键要点2"]
|
||||
"key_points": ["关键要点1", "关键要点2"],
|
||||
"can_reply": true/false,
|
||||
"reply_suggestions": [
|
||||
{"text": "回复内容", "is_simple": true/false},
|
||||
{"text": "回复内容", "is_simple": true/false},
|
||||
{"text": "回复内容", "is_simple": true/false}
|
||||
]
|
||||
}
|
||||
|
||||
其中 subject 字段不能照抄原邮件主题,必须是你总结生成的简短标题。
|
||||
其中:
|
||||
- subject 不能照抄原邮件主题,必须是你总结生成的简短标题
|
||||
- can_reply 为 false 表示无需回复或不适合建议回复(此时忽略 reply_suggestions)
|
||||
- is_simple 为 true 表示纯确认性回复(如"好的""收到"),用户选择后可直发
|
||||
- is_simple 为 false 表示涉及实质内容,需要用户确认再发送
|
||||
- 每条回复控制在 50 字以内
|
||||
只返回 JSON,不要包含任何其他文字。"""
|
||||
|
||||
|
||||
@@ -35,46 +46,6 @@ def summarize_email(ai_cfg: AIConfig, recipient: str, subject: str, sender: str,
|
||||
"response_format": {"type": "json_object"},
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {ai_cfg.api_key}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
return _call_deepseek(ai_cfg, payload)
|
||||
|
||||
|
||||
REPLY_PROMPT = """你是一个邮件回复助手。根据以下邮件内容生成3个建议回复。
|
||||
|
||||
返回 JSON:
|
||||
{
|
||||
"can_reply": true/false,
|
||||
"suggestions": [
|
||||
{"text": "回复内容", "is_simple": true/false},
|
||||
{"text": "回复内容", "is_simple": true/false},
|
||||
{"text": "回复内容", "is_simple": true/false}
|
||||
]
|
||||
}
|
||||
|
||||
- can_reply 为 false 时表示无需回复或不适合自动建议(此时忽略 suggestions)
|
||||
- is_simple 为 true 表示纯确认性回复(如"好的""收到""明白"),用户选择后可直接发送
|
||||
- is_simple 为 false 表示涉及实质内容,需要用户确认后再发送
|
||||
- 每条回复控制在 50 字以内
|
||||
只返回 JSON,不要包含任何其他文字。"""
|
||||
|
||||
|
||||
@retry()
|
||||
def generate_reply_suggestions(ai_cfg: AIConfig, sender: str, subject: str, body: str) -> dict:
|
||||
content = f"发件人: {sender}\n主题: {subject}\n正文:\n{body[:4000]}"
|
||||
|
||||
payload = {
|
||||
"model": ai_cfg.model,
|
||||
"messages": [
|
||||
{"role": "system", "content": REPLY_PROMPT},
|
||||
{"role": "user", "content": content},
|
||||
],
|
||||
"response_format": {"type": "json_object"},
|
||||
}
|
||||
|
||||
return _call_deepseek(ai_cfg, payload)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user