Translator

Static Methods

static availability

static async availability(options) => AIModelAvailability

Get the availability of the on-device language model.

Options (optional)

Returns the availability

static compatibility extension web

static async compatibility(options) => AIModelCoreCompatibility

Get the availability of the on-device language model.

Options (optional)

Returns the compatibility

static create

static async create(options) => Translator

Creates a new embedding session

Options (optional)

Returns a new Translator session that can be prompted with the pre-provided configuration


Properties

gpuEngine extension web

AIModelGpuEngine

dtype extension web

AIModelDtype

flashAttention extension web

boolean

contextSize

number

inputQuota

number

repeatPenalty extension web

number

sourceLanguage

string

targetLanguage

string


Methods

translate

async (input, options) => string

See translateStreaming

translateStreaming

(input, options) => ReadableStream

This prompts the language model to translate the provided text. The returned stream should contain the translation

Input

A string to be translated

Options (optional)

signal optional AbortSignal

Returns a readable stream that updates each time new tokens are available from the language model

measureInputUsage

async (input, options) => number

Measures the prompt usage of the input

Input

A string

Options (optional)

signal optional AbortSignal

Returns prompt usage based on the input

Last updated