sarvamai-go SDK Documentation
Text

Translate

`Text.Translate` for text-to-text translation.

Signature

func (c *TextClient) Translate(ctx context.Context, input string, sourceLang LanguageCode, targetLang LanguageCode, options ...translateOption) (*TranslateResponse, error)

Options

OptionTypeNotes
WithSpeakerGenderGenderMale|GenderFemaleno extra client-side validation
WithModeTranslateModemodel-dependent validation
WithModelModelMayura|ModelSarvamTranslatecontrols validation profile
WithOutputScriptOutputScript*only valid for ModelMayura
WithNumeralsFormatinternational|nativeno extra client-side enum validation

Valid / invalid combinations

CombinationResult
ModelMayura + ModeModernColloquialValid
ModelSarvamTranslate + ModeFormalValid
ModelSarvamTranslate + any non-formal modeValidation error
ModelMayura + OutputScriptRomanValid
ModelSarvamTranslate + any WithOutputScriptValidation error
model omitted + non-formal modeValidation error
model omitted + WithOutputScript(...)Validation error

Validation rules

  1. input must be non-empty.
  2. Input max length:
    • 1000 for ModelMayura
    • 2000 for ModelSarvamTranslate (and when model is omitted)
  3. source_language_code and target_language_code must be valid for selected model language set.
  4. Mode and output script follow model rules in table above.

Response

FieldType
RequestID*string
TranslatedTextstring
SourceLanguageCodelanguages.Code

Example

resp, err := client.Text.Translate(
    ctx,
    "Namaste, aap kaise ho?",
    text.LanguageEnIN,
    text.LanguageHiIN,
    text.WithModel(text.ModelMayura),
    text.WithMode(text.ModeFormal),
    text.WithOutputScript(text.OutputScriptFullyNative),
)
if err != nil {
    panic(err)
}
fmt.Println(resp.TranslatedText)

On this page