fix(wechat-bot): 修复 AGNES 媒体生成失败——优化步骤相对导入路径错误(从未生效)+ 国内模型直连 + 内容策略重试
This commit is contained in:
1 parent
fd2011b93e
commit
7739f17594
2 files changed
+52
-9
No files matched your search
@@ -33,6 +33,7 @@ def _proxy_for_url(url: str) -> str | None:
|
||||
"""按目标域名选择是否走代理(与 chat.py 同逻辑)。
|
||||
|
||||
2026-07-15 调整:AGNES 改走香港代理(实测延迟更低),不再直连。
|
||||
国内域名(尊重 NO_PROXY)直连,更稳定。
|
||||
"""
|
||||
import os
|
||||
host = (_urlparse(url).hostname or "").lower()
|
||||
@@ -40,6 +41,10 @@ def _proxy_for_url(url: str) -> str | None:
|
||||
return _HK_PROXY
|
||||
if "qihuyun.com" in host:
|
||||
return None
|
||||
_no_proxy = [h.strip().lower() for h in os.environ.get("NO_PROXY", "").split(",") if h.strip()]
|
||||
for _np in _no_proxy:
|
||||
if host == _np or host.endswith("." + _np) or _np in host:
|
||||
return None
|
||||
return os.environ.get("HTTPS_PROXY") or os.environ.get("HTTP_PROXY") or "http://172.18.0.1:7890"
|
||||
|
||||
|
||||
@@ -78,8 +83,10 @@ def _call_real_llm(db: Session, user=None, prompt: str = "", platform: str = "im
|
||||
if ai_model:
|
||||
try:
|
||||
result = _run_async(_generate_media(db, ai_model, prompt, user_id))
|
||||
except Exception as e:
|
||||
result = f"(媒体生成失败:{e})"
|
||||
except Exception:
|
||||
# 任何未预期异常(如 AGNES 连接重置)统一兜底为友好提示,
|
||||
# 绝不直接把原始异常(如 "Server disconnected")甩给用户
|
||||
result = "⚠️ 媒体生成暂时失败(连接或服务波动),请稍后重试。"
|
||||
if result:
|
||||
# IM 不渲染 HTML,把 <img>/<video> 还原为纯文本链接返回
|
||||
s = result.strip()
|
||||
|
||||
Reference in new issue
Block a user