FakeOnDeviceLlm

class FakeOnDeviceLlm(val supportsImage: Boolean = false, available: Boolean = true, capabilitiesOverride: AiCapabilities? = null) : OnDeviceLlm(source)

A scriptable OnDeviceLlm test double — no real model, no device, no :ai backend SDK — so any app can exercise its own AI-branching (a success string, a typed AiFailure, a chunked stream) without shipping a 500MB model or needing AICore-class hardware just to run its tests.

Queue as many outcomes as a test needs with enqueueSuccess/enqueueFailure/ enqueueStreamChunks — each generate/generateStream call consumes the next queued entry, in order. Once the queue runs dry the LAST entry keeps repeating, so a test that only cares about the first call doesn't have to script every call that follows it. An empty queue answers AiFailure.EmptyReply (a call) / an empty stream — the same shape a real backend gives back when it has nothing to say, rather than throwing on an un-scripted test.

Constructors

Link copied to clipboard
constructor(supportsImage: Boolean = false, available: Boolean = true, capabilitiesOverride: AiCapabilities? = null)

Properties

Link copied to clipboard
open override val supportsImage: Boolean

Functions

Link copied to clipboard
open suspend override fun capabilities(): AiCapabilities
Link copied to clipboard

The next generate call fails with reason.

Link copied to clipboard
fun enqueueStreamChunks(vararg chunks: String)

The next generateStream call emits chunks in order, one per element, then completes.

Link copied to clipboard

The next generate call returns text.

Link copied to clipboard
open suspend override fun generate(prompt: String): AiResult<String>
open suspend override fun generate(parts: List<LlmPart>): AiResult<String>
Link copied to clipboard
open override fun generateStream(prompt: String): Flow<String>
open override fun generateStream(parts: List<LlmPart>): Flow<String>
Link copied to clipboard
open override fun isAvailable(): Boolean
Link copied to clipboard
fun setAvailable(value: Boolean)

Flips what isAvailable (and, absent setCapabilities, the inherited capabilities) reports.

Link copied to clipboard
fun setCapabilities(capabilities: AiCapabilities)

Overrides capabilities outright — otherwise it derives from isAvailable, same as the real default.