QVAC Logo

translate( )

Translates text from one language to another using a specified translation model. Supports both NMT (Neural Machine Translation) and LLM models.

function translate(params: TranslateClientParams, options?: { forceNewConnection?: boolean; profiling?: { enabled?: boolean; includeServerBreakdown?: boolean; mode?: "summary" | "verbose" }; timeout?: number }): { stats: Promise<{ processedTokens: number; processingTime: number } | —>; text: Promise<string>; tokenStream: AsyncGenerator<string> }

Parameters

NameTypeRequired?Description
paramsTranslateClientParamsTranslation configuration object
options`{ forceNewConnection?: boolean; profiling?: { enabled?: boolean; includeServerBreakdown?: boolean; mode?: "summary""verbose" }; timeout?: number }`

Returns

{ stats: Promise<{ processedTokens: number; processingTime: number } |>; text: Promise<string>; tokenStream: AsyncGenerator<string> }
FieldTypeDescription
statsPromise
textPromise
tokenStreamAsyncGenerator

Throws

ErrorWhen
When translation fails with an error message or when language detection fails

Example

// Streaming mode (default)
const result = translate({
  modelId: "modelId",
  text: "Hello world",
  from: "en",
  to: "es"
  modelType: "llm",
});

for await (const token of result.tokenStream) {
  console.log(token);
}

// Non-streaming mode
const response = translate({
  modelId: "modelId",
  text: "Hello world",
  from: "en",
  to: "es"
  modelType: "llm",
  stream: false,
});

console.log(await response.text);

On this page