Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a517768083 | ||
|
|
e0c2110c09 |
No files matched your search
@@ -60,6 +60,7 @@ def ai_process(cfg: Config, user: UserConfig, acct_idx: int, mail: Email, tg_msg
|
||||
"original_recipient": mail.recipient,
|
||||
"original_reply_to": mail.reply_to,
|
||||
"original_cc": mail.cc,
|
||||
"original_subject": mail.subject,
|
||||
"acct_idx": acct_idx,
|
||||
"account_email": mail.account_email,
|
||||
"uid": mail.uid,
|
||||
@@ -89,6 +90,7 @@ def tg_send_and_mark(cfg: Config, user: UserConfig, info: dict):
|
||||
"original_recipient": info.get("original_recipient", ""),
|
||||
"original_cc": info.get("original_cc", ""),
|
||||
"original_reply_to": info.get("original_reply_to", ""),
|
||||
"original_subject": info.get("original_subject", ""),
|
||||
"account_email": info.get("account_email", ""),
|
||||
"account_idx": info["acct_idx"],
|
||||
"sender": info["data"].get("sender", ""),
|
||||
|
||||
+18
-9
@@ -310,16 +310,18 @@ def _do_regen(bot_token: str, cfg: Config, chat_id: int, msg_id: int, ctx: dict,
|
||||
_show_ai_suggestions(bot_token, chat_id, msg_id, new_suggestions, comparison)
|
||||
|
||||
|
||||
def _do_ai_hint(bot_token: str, cfg: Config, chat_id: int, conv: dict, ctx: dict, hint: str):
|
||||
"""在 AI 线程池中根据用户提示生成回复"""
|
||||
def _do_ai_hint(bot_token: str, cfg: Config, chat_id: int, conv: dict, ctx: dict, hint_history: list[str]):
|
||||
"""在 AI 线程池中根据用户提示生成回复(支持多轮追问)"""
|
||||
user = find_user_by_chat_id(cfg, chat_id)
|
||||
if not user:
|
||||
return
|
||||
style = conv.get("reply_style", "short")
|
||||
# 拼接历史提示作为上下文
|
||||
combined_hint = " → ".join(hint_history)
|
||||
try:
|
||||
result = generate_more_replies(
|
||||
user.ai, ctx["sender"], ctx["subject"], ctx["original_body"],
|
||||
conv.get("all_suggestions", []), user_hint=hint, style=style,
|
||||
conv.get("all_suggestions", []), user_hint=combined_hint, style=style,
|
||||
)
|
||||
new_suggestions = result["suggestions"]
|
||||
comparison = result.get("comparison", "")
|
||||
@@ -332,9 +334,10 @@ def _do_ai_hint(bot_token: str, cfg: Config, chat_id: int, conv: dict, ctx: dict
|
||||
conv["all_suggestions"].extend(new_suggestions)
|
||||
conv["comparison"] = comparison
|
||||
conv["state"] = "ai_reply_selection"
|
||||
conv["hint_history"] = hint_history
|
||||
conv.pop("prompt_msg_id", None)
|
||||
save_conversation(chat_id, conv)
|
||||
logger.info("[ai_hint] 根据提示生成 %d 条新回复", len(new_suggestions))
|
||||
logger.info("[ai_hint] 根据提示生成 %d 条新回复 (历史 %d 条)", len(new_suggestions), len(hint_history))
|
||||
_show_ai_suggestions(bot_token, chat_id, conv["summary_msg_id"], new_suggestions, comparison)
|
||||
|
||||
|
||||
@@ -360,7 +363,7 @@ def _handle_callback(bot_token: str, cfg: Config, cb: dict):
|
||||
action = parts[0]
|
||||
|
||||
ctx = load_email_context(msg_id)
|
||||
subject = ctx["subject"] if ctx else "?"
|
||||
subject = ctx.get("original_subject") or ctx["subject"] if ctx else "?"
|
||||
logger.info("TG 回调: action=%s msg_id=%d subject=%s", action, msg_id, subject)
|
||||
|
||||
if action == CALLBACK_VIEW_ORIG and ctx:
|
||||
@@ -499,8 +502,10 @@ def _handle_callback(bot_token: str, cfg: Config, cb: dict):
|
||||
if conv and conv.get("summary_msg_id") == msg_id:
|
||||
conv["state"] = "awaiting_ai_hint"
|
||||
conv["prompt_msg_id"] = prompt_msg_id
|
||||
if "hint_history" not in conv:
|
||||
conv["hint_history"] = []
|
||||
save_conversation(chat_id, conv)
|
||||
logger.info(" 等待用户输入 AI 提示")
|
||||
logger.info(" 等待用户输入 AI 提示 (历史 %d 条)", len(conv["hint_history"]))
|
||||
|
||||
elif action == CALLBACK_CANCEL:
|
||||
conv = load_conversation(chat_id)
|
||||
@@ -616,13 +621,17 @@ def _handle_message(bot_token: str, cfg: Config, msg: dict):
|
||||
if prompt_msg_id:
|
||||
delete_message(bot_token, chat_id_str, prompt_msg_id)
|
||||
|
||||
# 追加到 hint 历史
|
||||
hint_history = conv.get("hint_history", [])
|
||||
hint_history.append(text)
|
||||
|
||||
# 更新消息为 AI 思考中
|
||||
_tg_req(bot_token, "editMessageText", {
|
||||
"chat_id": chat_id, "message_id": conv["summary_msg_id"],
|
||||
"text": "🤖 *AI思考中…*", "parse_mode": "MarkdownV2",
|
||||
})
|
||||
# 丢到 AI 线程池处理
|
||||
_ai_pool.submit(_do_ai_hint, bot_token, cfg, chat_id, conv, ctx, text)
|
||||
# 丢到 AI 线程池处理,传入完整 hint 历史
|
||||
_ai_pool.submit(_do_ai_hint, bot_token, cfg, chat_id, conv, ctx, hint_history)
|
||||
|
||||
|
||||
def _show_ai_suggestions(bot_token: str, chat_id: int, msg_id: int,
|
||||
@@ -725,7 +734,7 @@ def _do_send_reply(bot_token: str, cfg: Config,
|
||||
to_addr = parseaddr(ctx["sender"])[1]
|
||||
if not to_addr:
|
||||
to_addr = ctx["sender"]
|
||||
subject = ctx["subject"]
|
||||
subject = ctx.get("original_subject") or ctx["subject"]
|
||||
|
||||
# 下载 Telegram 附件到本地
|
||||
local_files = []
|
||||
|
||||
Reference in New Issue
Block a user