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
statsPromiseResolves with translation performance metrics (processed tokens and processing time), or undefined if profiling is not enabled
textPromiseResolves with the full translated text once translation is complete
tokenStreamAsyncGeneratorYields translated tokens as they are generated in real-time

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