LiteRtLmFfiClient class
High-level Dart wrapper around the LiteRT-LM C API.
Provides a clean async interface over the native C functions, managing memory and translating C callbacks into Dart Streams.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInitialized → bool
-
no setter
- nativeLogPath → String?
-
Path to the redirected native stderr log (LiteRT-LM absl/glog output).
Set after
_ensureBindingsruns the stderr redirect; null on platforms where redirection isn't wired (currently it works on macOS + iOS).no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
cancelGeneration(
) → void - Cancel ongoing generation.
-
chat(
String text, {Uint8List? imageBytes, Uint8List? audioBytes, bool enableThinking = false}) → Stream< String> - Send a message and get streaming response as plain text chunks.
-
chatRaw(
String text, {Uint8List? imageBytes, Uint8List? audioBytes, bool enableThinking = false}) → Stream< String> -
Same as chat but yields raw SDK JSON chunks without
extractTextFromResponsemapping. Required by Gemma 4 path so callers can read the structuredtool_callsfield viaextractToolCalls. -
closeConversation(
) → void - Close the current conversation.
-
createConversation(
{String? systemMessage, String? toolsJson, double temperature = 0.8, int topK = 40, double? topP, int seed = 1}) → void - Create a new conversation with optional system message and tools.
-
dumpNativeLog(
) → void -
Reads back the native log file (set by stream_proxy_redirect_stderr) and
pipes its contents through debugPrint in 800-char chunks. Surfaces
absl/glog output (model load timing, accelerator init, sampler dlopen,
KV-cache prefill, etc.) that's redirected to a file by
stream_proxy_redirect_stderrand wouldn't otherwise reach the Flutter console / test harness. -
initialize(
{required String modelPath, String backend = 'gpu', int maxTokens = 2048, String? cacheDir, bool enableVision = false, int maxNumImages = 0, bool enableAudio = false}) → Future< void> - Initialize the engine with model path and settings.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sendMessage(
String messageJson, {String? extraContext}) → Future< String> - Send a text message and get the full response (sync C API, non-blocking Dart).
-
sendMessageStreamRaw(
String messageJson, {String? extraContext}) → Stream< String> - Send a raw JSON message and get streaming response.
-
shutdown(
) → void - Shutdown the engine and release all resources.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
buildMessageJson(
String text, {Uint8List? imageBytes, Uint8List? audioBytes}) → String - Build the JSON message for the Conversation API.
-
extractTextFromResponse(
String jsonStr) → String - Extract text from a LiteRT-LM JSON response chunk.