feat(qualite): retenter automatiquement les traductions livrees dans la mauvaise ecriture
Le defaut le plus sournois du pipeline etait silencieux : de l'arabe livre pour une cible persane (meme ecriture, mauvaise langue) passe inapercu et part chez le lecteur. Desormais chaque lot traduit est verifie par le detecteur d'ecritures, et chaque segment fautif est redemande une fois au moteur avec une consigne renforcee (nom de la langue + lettres specifiques, ex. persan پ چ ژ گ). La seconde tentative ne remplace la premiere que si elle passe le meme controle. - services/quality/script_detector.py : extraction d'un controle script_issue() reutilisable ; detect_arabic_variant signale des ormais un long texte en ecriture arabe sans aucune lettre specifique de la langue cible (arabe pur livre pour du persan/ourdou/pachto) - translators/segments.py : retry_wrong_script() + construction de la consigne renforcee, sans jamais faire echouer le travail - Word, Excel, PDF : branchement apres la memoire de traduction et les validations humaines ; le texte inchange (chiffres, noms propres) ne declenche jamais de retentative - 14 tests nouveaux (tests/test_translators/test_script_retry.py)
This commit is contained in:
@@ -763,6 +763,25 @@ class WordTranslator:
|
||||
)
|
||||
miss_pos += 1
|
||||
|
||||
# Wrong-script guard: re-ask once (with a reinforced instruction)
|
||||
# for translations delivered in the wrong alphabet — e.g. Arabic
|
||||
# delivered for a Persian target, which looks almost right to a
|
||||
# non-reader and ships unnoticed.
|
||||
from translators.segments import retry_wrong_script
|
||||
|
||||
def _retry_translate(retry_texts, hint):
|
||||
if self._provider is not None:
|
||||
return self._translate_with_provider(
|
||||
retry_texts, target_language, source_language, extra_prompt=hint
|
||||
)
|
||||
return self._translate_with_legacy(
|
||||
retry_texts, target_language, source_language, extra_prompt=hint
|
||||
)
|
||||
|
||||
translated, _script_fixed = retry_wrong_script(
|
||||
texts, translated, target_language, _retry_translate
|
||||
)
|
||||
|
||||
recorder = getattr(self, "_segment_recorder", None)
|
||||
if recorder is not None:
|
||||
recorder.record_pairs(zip(texts, translated))
|
||||
@@ -776,7 +795,8 @@ class WordTranslator:
|
||||
return dict(self._translation_stats)
|
||||
|
||||
def _translate_with_provider(
|
||||
self, texts: List[str], target_language: str, source_language: str
|
||||
self, texts: List[str], target_language: str, source_language: str,
|
||||
extra_prompt: Optional[str] = None,
|
||||
) -> List[str]:
|
||||
"""Translate using the TranslationProvider.translate_batch() interface."""
|
||||
from services.providers.base import TranslationProvider as NewTranslationProvider
|
||||
@@ -794,8 +814,12 @@ class WordTranslator:
|
||||
if is_new_style:
|
||||
from services.providers.schemas import TranslationRequest
|
||||
custom_prompt = getattr(self, "_custom_prompt", None)
|
||||
if extra_prompt:
|
||||
custom_prompt = (
|
||||
f"{custom_prompt}\n\n{extra_prompt}" if custom_prompt else extra_prompt
|
||||
)
|
||||
metadata = {"custom_prompt": custom_prompt} if custom_prompt else None
|
||||
|
||||
|
||||
requests = [
|
||||
TranslationRequest(
|
||||
text=t,
|
||||
@@ -809,7 +833,7 @@ class WordTranslator:
|
||||
translated = [resp.translated_text for resp in responses]
|
||||
else:
|
||||
translated = self._provider.translate_batch(texts, target_language, source_language)
|
||||
|
||||
|
||||
# Fallback: keep original text for any empty/failed result
|
||||
return [
|
||||
t if (t and t.strip()) else orig
|
||||
@@ -817,9 +841,15 @@ class WordTranslator:
|
||||
]
|
||||
|
||||
def _translate_with_legacy(
|
||||
self, texts: List[str], target_language: str, source_language: str
|
||||
self, texts: List[str], target_language: str, source_language: str,
|
||||
extra_prompt: Optional[str] = None,
|
||||
) -> List[str]:
|
||||
"""Fallback to legacy translation_service for backward compatibility."""
|
||||
"""Fallback to legacy translation_service for backward compatibility.
|
||||
|
||||
The legacy service has no custom-prompt parameter: extra_prompt is
|
||||
accepted for signature parity but cannot be forwarded — the retry
|
||||
still happens, just without the reinforced instruction.
|
||||
"""
|
||||
from services.translation_service import translation_service
|
||||
|
||||
_log_info(
|
||||
|
||||
Reference in New Issue
Block a user