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): { stats: Promise<any>; text: Promise<string>; tokenStream: AsyncGenerator<string> }

Description

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

Parameters

NameTypeRequired?Description
paramsTranslateClientParamsTranslation configuration object

Returns

{ stats: Promise<any>; text: Promise<string>; tokenStream: AsyncGenerator<string> }

Examples

// 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