fix(translate): 拦截引擎错误 marker + pipeline 严格 status 判定,避免 TMT AuthFailure 伪装 ok
This commit is contained in:
@@ -234,7 +234,21 @@ class TranslationService:
|
||||
if res is None:
|
||||
raise RuntimeError(f"translation failed for {chars} chars (engine={engine.name})")
|
||||
|
||||
# 4) 写缓存 — 只缓存真实翻译结果;失败/降级文本不缓存(避免污染 30 天)
|
||||
# 4) 校验翻译结果 — 如果文本里包含错误 marker(腾讯 TMT SDK
|
||||
# 异常时偶尔把错误信息当作"翻译结果"返回,导致 pipeline 误判为 ok)
|
||||
# 这种情况下我们要主动抛异常,触发 fallback 或标 failed
|
||||
if res.engine != "cache" and res.engine != "skip":
|
||||
for marker in ("[翻译失败", "[本条未翻译", "AuthFailure", "TencentCloudSDKException"):
|
||||
if marker in res.text:
|
||||
logger.warning(
|
||||
"engine %s returned error-marker text (marker=%s), treating as failure",
|
||||
res.engine, marker,
|
||||
)
|
||||
raise RuntimeError(
|
||||
f"engine={res.engine} returned error-marker '{marker}': {res.text[:120]}"
|
||||
)
|
||||
|
||||
# 5) 写缓存 — 只缓存真实翻译结果;失败/降级文本不缓存(避免污染 30 天)
|
||||
if res.engine in ("spark", "zhipu", "tencent", "tencent_maas", "agnes", "nllb") and not res.cached:
|
||||
if "[翻译失败" not in res.text and "[本条未翻译" not in res.text:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user