Engine class final

One .litertlm model loaded by the page's @litert-lm/core runtime.

Properties

activationDataType → ActivationDataType?
Always null on the web: the runtime takes no activation type.
final
audioBackend → Backend?
Where the audio encoder runs, as the runtime resolved it; null when the engine loaded none.
final
backend → Backend
The text model's backend, as the runtime resolved it: WebGPU (Backend.gpu, also for a web export the runtime runs through its legacy GPU executor) or WebAssembly (Backend.cpu).
final
bundleInfo → BundleInfo?
Always null on the web: the page cannot read the file by path.
final
hashCode → int
The hash code for this object.
no setterinherited
maxNumTokens → int
The context window the runtime resolved: the one asked for, else the bundle's own (8192 for Gemma 4 E2B's GPU export); 0 when it reported none. On the web it is not raised to the 1024 tokens the native CPU and GPU executors need: the web runtime takes what it is given.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
visionBackend → Backend?
Where the vision encoder runs, as the runtime resolved it; null when the engine loaded none.
final

Methods

close() → Future<void>
Closes every conversation — each waits, at most 30 s, for its generation to end — and deletes the engine, after any conversation still being created. A reply still streaming ends with ConversationClosedException; a later send on any of its conversations, and every other call on the engine, is a StateError. Fails with the page's LiteRtLmPagePoisonedError when a stopped generation never ended: the engine is then left to the page (its delete would wait on that generation for good).
createConversation([ConversationConfig? config]) → Future<Conversation>
Starts a conversation, with its own @litert-lm/core conversation.
detokenize(List<int> ids) → Future<String>
Refused on the web: @litert-lm/core exposes no detokenizer.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
scoreTargets(String prompt, List<String> targets, {CancelSignal? cancel}) → Future<ScoringRun>
Refused on the web: @litert-lm/core has no text scoring and no rewind.
tokenize(String text) → Future<List<int>>
Refused on the web: @litert-lm/core counts a conversation's tokens (getTokenCount()), but exposes no tokenizer for a text.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

create(EngineConfig config) → Future<Engine>
Loads config.modelPath — a URL the page can fetch (blob:, https:) — on config.backend: WebGPU for Backend.gpu, WebAssembly for Backend.cpu (whose threadCount becomes the runtime's number_of_threads). One attempt, no fallback. Pass Backend.gpu for Gemma 4's GPU export: the default Backend.cpu fails it at the first send (0.19.0: "Environment was not initialized during streaming.").