#973 微信Bot文本回复慢+间歇空修复
CI / gate (push) Has been cancelled

根因: 多轮对话时图片URL(含AWS token)存进历史+104技能清单注入prompt, 导致推理模型响应慢(72s)且间歇返回空content。修复: 1.IM侧精简prompt(db=None只注入静态文档) 2.空content重试(同模型最多3轮) 3.图片回复存[图片]占位符不存URL 4.历史每条截断500字符。验证: 你好15s/1+1=4s可正常回复。
This commit is contained in:
qihu-bot committed 2026-08-18 11:15:50 +08:00
1 parent 1c0dc59842
commit 9cf4378bf5
2 files changed
+13 -8

No files matched your search

+7 -6
View File
@@ -131,7 +131,11 @@ def _recent_history(user_id: str, limit: int = 6) -> str:
for r in reversed(rows):
dd = _row_to_dict(r)
role = "用户" if dd["role"] == "user" else "七虎AI"
pairs.append(f"{role}:{dd['content']}")
content = dd.get("content") or ""
# #973:每条历史最多 500 字符,防止超长图片 URL/完整清单撑爆多轮 prompt
if len(content) > 500:
content = content[:500] + "…"
pairs.append(f"{role}:{content}")
return "\n".join(pairs)
except Exception:
return ""
@@ -654,11 +658,8 @@ def _wechat_receiver_loop(account_id: int):
ok, ret, _ = _wechat_send_media(baseurl, bot_token, sender, ctx, media_type, media_url)
# 对话历史里存可渲染的媒体标签(经平台中转,AI 聊天 WeXin Bot 窗与历史页均可内联显示)
relay_url = _platform_relay_url(media_url)
reply_for_log = (
f'<img src="{relay_url}" alt="生成图片"/>'
if media_type == "image"
else f'<video src="{relay_url}" controls></video>'
)
# #973:对话历史只存简短占位符,不存超长 relay URL(含 AWS token,会撑爆多轮 prompt)
reply_for_log = "[图片]" if media_type == "image" else "[视频]"
else:
reply_text = reply if isinstance(reply, str) else str(reply)
ok, ret, _ = _wechat_send_message(baseurl, bot_token, sender, ctx, reply_text)