Skip to content
4 min read · 818 words

Interface: TransformersJsGenerationAdapterOptions ​

Defined in: src/batteries/generation/transformers_js/types.ts:178

Constructor options for @nhtio/adk/batteries/generation/transformers_js/adapter!TransformersJsGenerationAdapter.

Remarks ​

Extends BaseGenerationAdapterOptions (required model, e.g. onnx-community/Janus-Pro-1B-ONNX — no default) with the transformers.js Janus knobs.

EXPERIMENTAL: this engine downloads/runs a ~2GB multimodal model and takes minutes per image on WASM/CPU. There is no WebGPU requirement (transformers.js auto-selects the ONNX Runtime execution provider), but expect this to be materially slower than the OpenAI/Gemini engines.

Extends ​

Properties ​

| Property | Type | Description | Inherited from | Defined in | | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | chatTemplate? | string | Default Janus chat template name forwarded to the processor call (e.g. 'text_to_image'), applied when a call omits its own. | - | src/batteries/generation/transformers_js/types.ts:226 | | createModel? | CreateTransformersJsGenerationModel | Override the model factory. Default: MultiModalityCausalLM.from_pretrained(model, …) via dynamic import. | - | src/batteries/generation/transformers_js/types.ts:189 | | createProcessor? | CreateTransformersJsGenerationProcessor | Override the processor factory. Default: AutoProcessor.from_pretrained(model, …) via dynamic import. | - | src/batteries/generation/transformers_js/types.ts:191 | | device? | string | Inference device forwarded to from_pretrained(). Default: transformers.js environment default. | - | src/batteries/generation/transformers_js/types.ts:193 | | doSample? | boolean | Default sampling knobs applied when a generate() call omits its own — see TransformersJsGenerateOptions for the per-knob provenance/verification notes. | - | src/batteries/generation/transformers_js/types.ts:216 | | dtype? | string | Quantization/precision dtype forwarded to from_pretrained(). | - | src/batteries/generation/transformers_js/types.ts:195 | | encodeImage? | EncodeRawImageFn | Test/runtime seam overriding how a resolved RawImage-like value is encoded to PNG bytes — see EncodeRawImageFn. Short-circuits the env-branch (toBlob/toSharp) entirely; the primary hermetic-test seam for generate(). | - | src/batteries/generation/transformers_js/types.ts:211 | | guidanceScale? | number | Default classifier-free-guidance scale (guidance_scale; CFG activates when > 1), applied when a call omits its own. | - | src/batteries/generation/transformers_js/types.ts:222 | | isAvailable? | () => boolean | Override the availability probe. Default: true whenever the peer is importable (env-neutral). | - | src/batteries/generation/transformers_js/types.ts:205 | | janusModel? | TransformersJsGenerationModel | A pre-built Janus model. When provided, the battery uses it directly and skips lazy creation. Named janusModel (not model) because model (from BaseGenerationAdapterOptions) is already the model id string. | - | src/batteries/generation/transformers_js/types.ts:185 | | model | string | Model id to generate/edit images with. Required, no default. For OpenAI this is e.g. gpt-image-1 or dall-e-3. | BaseGenerationAdapterOptions.model | src/batteries/generation/openai/types.ts:71 | | modelSource? | TransformersJsGenerationModelSource | Custom model-source resolver (OPFS / separate source / bundled bytes). When set, model files load through it behind the global-env mutex; otherwise straight from HF (unchanged). See TransformersJsGenerationModelSource. | - | src/batteries/generation/transformers_js/types.ts:201 | | onCompiling? | BatteryLifecycleCallback | Engine/graph/shader compilation after download, before the first token. A COARSE marker: the on-device runtimes (LiteRT Engine.create, transformers.js from_pretrained) expose the boundary — download done, opaque WebGPU/WASM graph build about to run — but NOT a progress stream, so progress is usually absent. Often the slowest part of a cold start; without this it was invisible. | BatteryLifecycleHooks.onCompiling | src/batteries/llm/chat_common/lifecycle.ts:95 | | onComplete? | BatteryLifecycleCallback | After the turn's output is parsed + persisted, before ack (fires per turn). | BatteryLifecycleHooks.onComplete | src/batteries/llm/chat_common/lifecycle.ts:105 | | onError? | BatteryLifecycleCallback | A load or generation failure (paired with nack). | BatteryLifecycleHooks.onError | src/batteries/llm/chat_common/lifecycle.ts:107 | | onGenerating? | BatteryLifecycleCallback | The generate call is in progress (fires per turn). Fires once immediately before the provider call for most engines; engines that stream per-step generation progress (e.g. a diffusion denoise loop) fire it REPEATEDLY during generation, each carrying a progress in 0..1. | BatteryLifecycleHooks.onGenerating | src/batteries/llm/chat_common/lifecycle.ts:103 | | onInitProgress? | TransformersJsGenerationProgressCallback | Called with model-load progress reports while weights download/compile. | - | src/batteries/generation/transformers_js/types.ts:203 | | onLifecycle? | BatteryLifecycleCallback | Fires on EVERY phase transition (the firehose). | BatteryLifecycleHooks.onLifecycle | src/batteries/llm/chat_common/lifecycle.ts:86 | | onLoading? | BatteryLifecycleCallback | Weights/runtime loading — may fire repeatedly with progress as the provider reports it. | BatteryLifecycleHooks.onLoading | src/batteries/llm/chat_common/lifecycle.ts:88 | | onReady? | BatteryLifecycleCallback | Engine/pipeline resolved and cached, before the first generation. | BatteryLifecycleHooks.onReady | src/batteries/llm/chat_common/lifecycle.ts:97 | | processor? | TransformersJsGenerationProcessor | A pre-built Janus processor. When provided, the battery uses it directly and skips lazy creation. | - | src/batteries/generation/transformers_js/types.ts:187 | | repetitionPenalty? | number | Default repetition penalty (repetition_penalty), applied when a call omits its own. | - | src/batteries/generation/transformers_js/types.ts:224 | | role? | string | Default conversation role used to build the single-turn prompt (Janus convention: '< | User | >'). | - | src/batteries/generation/transformers_js/types.ts:228 | | temperature? | number | Default sampling temperature (temperature), applied when a call omits its own. | - | src/batteries/generation/transformers_js/types.ts:218 | | topK? | number | Default top-k cutoff (top_k), applied when a call omits its own. | - | src/batteries/generation/transformers_js/types.ts:220 |