OnDeviceLlm

interface OnDeviceLlm

A single-shot on-device text LLM tier. Kept deliberately tiny — one availability gate and one text-in/text-out call — so each platform's actual (ML Kit GenAI on Android, Foundation Models on iOS, unavailable elsewhere) is a thin wrapper, and DefaultJobIntelligence never has to know which backend ran.

generate returns null on any failure or when the model isn't resident, so the caller degrades to the heuristic tier instead of throwing.

Inheritors

Properties

Link copied to clipboard

True when this backend accepts an LlmPart.Image in generate. False = text-only.

Functions

Link copied to clipboard
abstract suspend fun generate(prompt: String): String?

Runs prompt on-device. Returns the model's text, or null when unavailable/declined/failed.

open suspend fun generate(parts: List<LlmPart>): String?

Multimodal entry point. Default maps a single LlmPart.Text onto generate (String) so every existing text-only actual (MediaPipe, Foundation Models, jvm) keeps working with zero changes. Backends that accept images (ML Kit GenAI) override this directly.

Link copied to clipboard
open fun generateStream(prompt: String): Flow<String>

Streaming variant of generate. Default replays the single-shot result as one emission so every existing actual keeps working with zero changes; backends with native token streaming (ML Kit GenAI) override this directly.

open fun generateStream(parts: List<LlmPart>): Flow<String>
Link copied to clipboard
abstract fun isAvailable(): Boolean

Cheap, synchronous floor — true only when the platform could run inference. NOT the authoritative runtime check (model residency is async); generate still guards internally.