fix(glossary): resolve data loss for non-FR/EN languages, fix prompt injection reference notes, and classic mode label wording
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m25s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m25s
This commit is contained in:
@@ -122,6 +122,7 @@ def format_glossary_for_prompt(
|
||||
terms: List[Dict[str, str]],
|
||||
source_lang: str = "fr",
|
||||
target_lang: str = "en",
|
||||
glossary_target_lang: str = "multi",
|
||||
) -> str:
|
||||
"""
|
||||
Format glossary terms for injection into an LLM system prompt.
|
||||
@@ -135,6 +136,7 @@ def format_glossary_for_prompt(
|
||||
terms: List of dicts with 'source', 'target', and optional 'translations'
|
||||
source_lang: ISO code of the source language
|
||||
target_lang: ISO code of the target language
|
||||
glossary_target_lang: ISO code of the glossary's target language configuration
|
||||
|
||||
Returns:
|
||||
Formatted string for LLM prompt
|
||||
@@ -166,8 +168,11 @@ def format_glossary_for_prompt(
|
||||
elif default_target:
|
||||
source_escaped = source.replace("'", "\\'")
|
||||
target_escaped = default_target.replace("'", "\\'")
|
||||
lines.append(f"- '{source_escaped}' → '{target_escaped}' (EN reference, adapt to {target_lang})")
|
||||
has_fallback = True
|
||||
if glossary_target_lang == target_lang:
|
||||
lines.append(f"- '{source_escaped}' → '{target_escaped}'")
|
||||
else:
|
||||
lines.append(f"- '{source_escaped}' → '{target_escaped}' (EN reference, adapt to {target_lang})")
|
||||
has_fallback = True
|
||||
# If neither specific nor default, skip the term
|
||||
|
||||
if not any(line.startswith("- ") for line in lines):
|
||||
@@ -192,6 +197,7 @@ def build_full_prompt(
|
||||
glossary_terms: Optional[List[Dict[str, str]]],
|
||||
source_lang: str = "fr",
|
||||
target_lang: str = "en",
|
||||
glossary_target_lang: str = "multi",
|
||||
) -> str:
|
||||
"""
|
||||
Build the complete prompt combining custom prompt and glossary.
|
||||
@@ -201,6 +207,7 @@ def build_full_prompt(
|
||||
glossary_terms: Optional list of glossary terms
|
||||
source_lang: ISO code of the source language
|
||||
target_lang: ISO code of the target language
|
||||
glossary_target_lang: ISO code of the glossary's target language configuration
|
||||
|
||||
Returns:
|
||||
Combined prompt string
|
||||
@@ -211,7 +218,9 @@ def build_full_prompt(
|
||||
parts.append(custom_prompt)
|
||||
|
||||
if glossary_terms:
|
||||
glossary_prompt = format_glossary_for_prompt(glossary_terms, source_lang, target_lang)
|
||||
glossary_prompt = format_glossary_for_prompt(
|
||||
glossary_terms, source_lang, target_lang, glossary_target_lang
|
||||
)
|
||||
if glossary_prompt:
|
||||
parts.append(glossary_prompt)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user