FakeOnDeviceAiPlatform class

In-memory platform implementation for unit and widget tests.

It keeps real session state, streams words as chunks and honours cancellation, so code written against the plugin behaves as on a device.

Inheritance

Constructors

FakeOnDeviceAiPlatform({FakeResponder? responder, OnDeviceAiAvailability availability = const OnDeviceAiAvailability(status: ModelFeatureStatus.available, reason: AvailabilityReason.ready, message: 'Fake on-device model ready.'), OnDeviceAiPlatformInfo info = const OnDeviceAiPlatformInfo(backend: OnDeviceAiBackend.appleFoundationModels), Duration chunkDelay = Duration.zero})

Properties

availability ↔ OnDeviceAiAvailability
State returned by getAvailability.
getter/setter pair
chunkDelay ↔ Duration
Pause between streamed chunks.
getter/setter pair
createdSessions → List<String>
Every session id ever created, in order.
final
downloadEvents ↔ List<ModelDownloadStatus>
Scripted download events for downloadModel.
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
info ↔ OnDeviceAiPlatformInfo
Capabilities returned by getPlatformInfo.
getter/setter pair
responder ↔ FakeResponder?
Produces replies; defaults to Fake reply to: <prompt>.
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sessions → Map<String, FakeSession>
Sessions that are currently open.
final

Methods

createSession({String? systemInstruction, List<OnDeviceAiTool>? tools, GenerationConfig? config}) → Future<String>
Creates a conversation and returns its id.
override
downloadModel() → Stream<ModelDownloadStatus>
Asks the OS / browser to download the model, reporting progress.
override
getAvailability() → Future<OnDeviceAiAvailability>
Current state of the native model, with a reason when it is not ready.
override
getPlatformInfo() → Future<OnDeviceAiPlatformInfo>
What the native backend can do.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openAICorePlayStore() → Future<bool>
Opens the Google AICore page in Play Store (Android only).
inherited
sessionAddImage(String sessionId, Uint8List imageBytes, {String mimeType = 'image/jpeg'}) → Future<void>
Adds a user image part to the pending turn.
override
sessionAddQuery(String sessionId, String text) → Future<void>
Adds a user text part to the pending turn.
override
sessionClose(String sessionId) → Future<void>
Releases the session.
override
sessionCountTokens(String sessionId, {String? text}) → Future<int>
Token count of the whole conversation, or of text when given.
override
sessionGetResponse(String sessionId, {GenerationConfig? config}) → Future<AiResponse>
Answers the pending turn.
override
sessionGetResponseStream(String sessionId, {GenerationConfig? config}) → Stream<String>
Answers the pending turn as a stream of text deltas.
override
sessionStopGeneration(String sessionId) → Future<void>
Cancels the generation in flight, if any.
override
toString() → String
A string representation of this object.
inherited

Operators

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