LlmTranslatorBroker class

Vendor-neutral LLM-backed translator. Pass any AiBroker (Anthropic, Gemini, OpenAI, or a custom one) and this class drives it through the same AiMessage / ChatRequest shape ai_broker already exposes — no per-provider message-type clones.

For the three common providers use the named factory constructors (LlmTranslatorBroker.claude, LlmTranslatorBroker.gemini, LlmTranslatorBroker.openai) which pre-fill a sensible default model.

Inheritance

Constructors

LlmTranslatorBroker({required String? apiKey, required AiBroker broker, required String model, String systemPrompt = defaultSystemPrompt, double temperature = 0.2, int maxTokens = 1000})
const
LlmTranslatorBroker.claude({required String apiKey, String model = 'claude-3-haiku-20240307', String systemPrompt = defaultSystemPrompt, double temperature = 0.2, int maxTokens = 1000, AiBroker? broker})
Anthropic Claude. Default model is the cheapest stable Haiku tier.
factory
LlmTranslatorBroker.gemini({required String apiKey, String model = 'gemini-1.5-flash-8b', String systemPrompt = defaultSystemPrompt, double temperature = 0.2, int maxTokens = 1000, AiBroker? broker})
Google Gemini. Default model is the lightweight 8B Flash tier.
factory
LlmTranslatorBroker.openai({required String apiKey, String model = 'gpt-4o-mini', String systemPrompt = defaultSystemPrompt, double temperature = 0.2, int maxTokens = 1000, AiBroker? broker})
OpenAI. Default model is the cheap, fast 4o-mini tier.
factory

Properties

apiKey String?
finalinherited
broker AiBroker
The underlying provider. Owns the HTTP call; this class only owns the prompt shape and the df_safer_dart error wrapping.
final
hashCode int
The hash code for this object.
no setterinherited
maxTokens int
Output ceiling. Defaults to 1000.
final
model String
Provider-specific model id, e.g. 'claude-3-haiku-20240307', 'gemini-1.5-flash-8b', 'gpt-4o-mini'.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
systemPrompt String
System instruction sent on every call. Defaults to a prompt that tells the model to act as an app-localization translator and to leave {...} / {{...}} placeholders untouched.
final
temperature double
Sampling temperature. Defaults to 0.2 — translation should be near-deterministic.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
translate({required List<AiMessage> contents}) Async<String>
override
translateSentence({required String text, required String languageCode, required String? countryCode}) Async<String>
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

defaultSystemPrompt → const String
Default system instruction. Exposed so callers can prepend extra guidance ('$defaultSystemPrompt\nAlways prefer formal address.') without losing the placeholder rule.