修改视频生成积分不足提示
This commit is contained in:
@@ -7,6 +7,7 @@ dist
|
|||||||
# core 后端环境变量需要进 CI 构建,放行它(其余 .env 仍忽略)
|
# core 后端环境变量需要进 CI 构建,放行它(其余 .env 仍忽略)
|
||||||
!core/backend/.env
|
!core/backend/.env
|
||||||
.venv
|
.venv
|
||||||
|
.idea/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
@@ -33,3 +34,4 @@ docs/bug_todo/
|
|||||||
|
|
||||||
# pnpm 本地内容寻址存储
|
# pnpm 本地内容寻址存储
|
||||||
.pnpm-store/
|
.pnpm-store/
|
||||||
|
|
||||||
|
|||||||
@@ -369,6 +369,8 @@ def classify_generation_error(
|
|||||||
compact_code = re.sub(r"[^a-z0-9]", "", provider_code.lower())
|
compact_code = re.sub(r"[^a-z0-9]", "", provider_code.lower())
|
||||||
|
|
||||||
# 内容审核必须先于 HTTP 403 判断:部分供应商会以 403 返回 policy violation。
|
# 内容审核必须先于 HTTP 403 判断:部分供应商会以 403 返回 policy violation。
|
||||||
|
if _contains(signal, "insufficient credit", "余额不足", "额度不足", "credit limit exceeded"):
|
||||||
|
return _build_error("user_credit_insufficient", operation, reference_id=reference_id)
|
||||||
if _contains(signal, "moderation_blocked", "safety_violation", "safety system", "content_policy", "policyviolation", "sensitivecontentdetected"):
|
if _contains(signal, "moderation_blocked", "safety_violation", "safety system", "content_policy", "policyviolation", "sensitivecontentdetected"):
|
||||||
return _build_error("content_rejected", operation, reference_id=reference_id)
|
return _build_error("content_rejected", operation, reference_id=reference_id)
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ class GenerationErrorClassifierTests(SimpleTestCase):
|
|||||||
self.assertEqual(error.code, "user_credit_insufficient")
|
self.assertEqual(error.code, "user_credit_insufficient")
|
||||||
self.assertEqual(error.action, "recharge")
|
self.assertEqual(error.action, "recharge")
|
||||||
|
|
||||||
|
def test_insufficient_credit_is_detected_without_manual_internal_kind(self):
|
||||||
|
error = classify_generation_error(
|
||||||
|
ValueError("insufficient credit"),
|
||||||
|
operation="video_generate",
|
||||||
|
)
|
||||||
|
self.assertEqual(error.code, "user_credit_insufficient")
|
||||||
|
self.assertEqual(error.action, "recharge")
|
||||||
|
self.assertIn("积分不足", error.fallback_message)
|
||||||
|
|
||||||
def test_moderation_takes_precedence_over_403(self):
|
def test_moderation_takes_precedence_over_403(self):
|
||||||
error = classify_generation_error(
|
error = classify_generation_error(
|
||||||
_http_error(403, "PolicyViolation", "safety_violation"),
|
_http_error(403, "PolicyViolation", "safety_violation"),
|
||||||
|
|||||||
Reference in New Issue
Block a user