LLM processor for the translator behaviour.
Summary
Functions
Builds a TranslateGemma-formatted prompt for translation.
Callback implementation for GettextTranslator.Processor.Translator.translate/2.
Translates a single message using the configured LLM provider, with optional additional instructions to guide the translation.
Checks if the given model name is a TranslateGemma model.
Functions
Builds a TranslateGemma-formatted prompt for translation.
TranslateGemma expects a single user message with a specific structure: professional translator persona, followed by two blank lines before the text.
Parameters
message- The text to translatesource_code- POSIX code of the source language (e.g., "en")target_code- POSIX code of the target language (e.g., "es")
Examples
iex> GettextTranslator.Processor.LLM.build_translategemma_prompt("Hello", "en", "es")
"You are a professional English (en) to Spanish (es) translator. " <>
"Your goal is to accurately convey the meaning and nuances of the original English text " <>
"while adhering to Spanish grammar, vocabulary, and cultural sensitivities.\n" <>
"Produce only the Spanish translation, without any additional explanations or commentary. " <>
"Please translate the following English text into Spanish:\n\n\nHello"
@spec translate( GettextTranslator.Processor.Translator.provider(), GettextTranslator.Processor.Translator.opts() ) :: {:ok, String.t()} | {:error, any()}
Callback implementation for GettextTranslator.Processor.Translator.translate/2.
@spec translate_single( GettextTranslator.Processor.Translator.provider(), map(), String.t() | nil ) :: {:ok, map()} | {:error, any()}
Translates a single message using the configured LLM provider, with optional additional instructions to guide the translation.
Parameters
provider- The provider config map fromParser.parse_provider/0opts- Map with:language_code,:message,:type, and optionally:plural_messageadditional_instructions- Optional string with extra instructions for the LLM
Returns
{:ok, %{translation: String.t(), plural_translation: String.t() | nil}}{:error, reason}
Checks if the given model name is a TranslateGemma model.
Examples
iex> GettextTranslator.Processor.LLM.translategemma?("translategemma-27b")
true
iex> GettextTranslator.Processor.LLM.translategemma?("gpt-4")
false