根因: 多轮对话时图片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:
1 parent
1c0dc59842
commit
9cf4378bf5
2 files changed
+13
-8
No files matched your search
@@ -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)
|
||||
|
||||
@@ -277,10 +277,11 @@ def _call_real_llm(db: Session, user=None, prompt: str = "", platform: str = "im
|
||||
f"mcp_tools={len(mcp_function_definitions)}"
|
||||
)
|
||||
|
||||
# 平台知识库注入(对齐 Web Chat——微信用户提问"平台有哪些技能"也能得到完整清单)
|
||||
# 平台知识库注入(#973:IM 侧精简——只注入静态文档,不注入 104 动态清单,
|
||||
# 避免 prompt 过长(6892字符)导致推理模型响应慢(63s)且间歇性返回空 content)
|
||||
kb_context = ""
|
||||
try:
|
||||
pk = get_platform_knowledge(db=db)
|
||||
pk = get_platform_knowledge(db=None)
|
||||
if pk:
|
||||
kb_context = f"【平台知识库——优先使用以下知识回答用户问题】\n{pk}"
|
||||
except Exception:
|
||||
@@ -420,6 +421,9 @@ def _call_real_llm(db: Session, user=None, prompt: str = "", platform: str = "im
|
||||
if round_num >= max_rounds - 1:
|
||||
break
|
||||
continue
|
||||
# #973:空 content 且未到最后一轮 → 重试(推理模型间歇性返回空)
|
||||
if not ai_content and round_num < max_rounds - 1:
|
||||
continue
|
||||
break
|
||||
|
||||
# 检查本轮调用是否成功
|
||||
|
||||
Reference in new issue
Block a user