feat(quality): A4 — L2 Pro premium judge (8 dims, gpt-4o, Pro-gated, opt-in)
Some checks failed
Deploy to Production / Build and Deploy (push) Has been cancelled

This commit is contained in:
2026-07-14 16:56:04 +02:00
parent 8d0fc818ef
commit c794eff823
6 changed files with 1143 additions and 0 deletions

View File

@@ -1455,6 +1455,49 @@ async def _run_translation_job(
except Exception:
pass
# ------------------------------------------------------------------
# Quality L2 layer (Track A4 — Pro premium judge)
# Stronger LLM (gpt-4o default), 8 dimensions, 15 samples.
# Gated to Pro+ plans (configurable via QUALITY_L2_TIER_GATE).
# Default OFF everywhere — observation first.
# Cost: ~$0.005$0.02/job (gpt-4o), ~$0.001/job (gpt-4o-mini).
# ------------------------------------------------------------------
if getattr(config, "QUALITY_L2_ENABLED", False) and quality_samples:
try:
from services.quality import run_l2_check
# Tier gate: Pro+ plans only (unless gate is disabled)
user_tier = (
_tier_for_quota(current_user.plan) if current_user else "free"
)
tier_gate_on = getattr(config, "QUALITY_L2_TIER_GATE", True)
if not tier_gate_on or user_tier in ("pro", "business", "enterprise"):
translated_chunks_for_l2 = [s["translated"] for s in quality_samples]
l2_result = await run_l2_check(
source_chunks=[""] * len(translated_chunks_for_l2),
translated_chunks=translated_chunks_for_l2,
target_lang=target_lang,
l0_failed_indices=l0_failed_indices,
job_id=job_id,
file_extension=file_extension,
max_samples=getattr(config, "QUALITY_L2_SAMPLE_SIZE", 15),
min_chunks=getattr(config, "QUALITY_L2_MIN_CHUNKS", 20),
log_only=getattr(config, "QUALITY_L2_LOG_ONLY", True),
)
else:
# Free/Starter user — skip L2 silently (gated)
logger.info(
"quality_l2_check_skipped",
job_id=job_id,
reason="tier_gated",
tier=user_tier,
)
except Exception as l2_err:
# L2 must NEVER break a job. Log and continue.
logger.warning(
f"Job {job_id}: quality L2 layer failed: {l2_err}"
)
if user_id:
# Determine cost factor based on selected provider and model
cost_factor = 1