feat: show recipient & AI-generated subject in summary

- AI now generates a concise subject title (not copy original)
- AI prompt includes recipient field in JSON schema
- Telegram message shows recipient and uses AI-generated title
This commit is contained in:
2026-07-02 20:05:16 +08:00
parent a6817d3e11
commit 279f8c50e7
3 changed files with 9 additions and 6 deletions

View File

@@ -8,7 +8,8 @@ SYSTEM_PROMPT = """你是一个邮件摘要助手。请分析邮件内容并以
返回格式必须严格遵循以下 JSON schema
{
"subject": "邮件主题",
"subject": "你概括的简短标题10字以内",
"recipient": "收件邮箱地址",
"sender": "发件人",
"summary": "50字以内的核心摘要",
"priority": "high/medium/low",
@@ -17,12 +18,13 @@ SYSTEM_PROMPT = """你是一个邮件摘要助手。请分析邮件内容并以
"key_points": ["关键要点1", "关键要点2"]
}
其中 subject 字段不能照抄原邮件主题,必须是你总结生成的简短标题。
只返回 JSON不要包含任何其他文字。"""
@retry()
def summarize_email(ai_cfg: AIConfig, subject: str, sender: str, body: str) -> dict[str, Any]:
content = f"发件人: {sender}\n主题: {subject}\n正文:\n{body[:4000]}"
def summarize_email(ai_cfg: AIConfig, recipient: str, subject: str, sender: str, body: str) -> dict[str, Any]:
content = f"收件人: {recipient}\n发件人: {sender}\n主题: {subject}\n正文:\n{body[:4000]}"
payload = {
"model": ai_cfg.model,

View File

@@ -29,7 +29,8 @@ def _process_account(cfg: Config, acct):
for mail in emails:
try:
logger.info(f" 正在摘要: {mail.subject}")
summary = summarize_email(cfg.ai, mail.subject, mail.sender, mail.body)
summary = summarize_email(cfg.ai, acct.username, mail.subject, mail.sender, mail.body)
summary["recipient"] = acct.username
text = format_summary(summary)
send_message(cfg.telegram, text)
seen_uids.append(mail.uid)

View File

@@ -23,10 +23,10 @@ def format_summary(data: dict) -> str:
icon = _priority_icon.get(priority, "")
lines = [
f"*📧 新邮件摘要*",
f"*📧 {_escape(data.get('subject', '邮件摘要'))}*",
f"━━━━━━━━━━━━━━━━━━",
f"*收件人:* {_escape(data.get('recipient', '未知'))}",
f"*发件人:* {_escape(data.get('sender', '未知'))}",
f"*主题:* {_escape(data.get('subject', '无主题'))}",
f"*优先级:* {icon} {priority.upper()}",
"",
_escape(data.get("summary", "")),