AIOnDeviceModel
Gemini Nano, the model in Android's AICore, through ML Kit's GenAI Prompt API. It answers without a network connection, and the conversation never leaves the device.
It runs on devices whose AICore offers Gemini Nano (recent Pixel, Samsung and other flagship phones), not on emulators. The model may need downloading first: status says whether it is Status.Downloadable or Status.Downloading, and download starts it.
It is a small model, good for short answers and for working with what is in the conversation. Its context holds a few thousand tokens, so the oldest turns of a long conversation are left out.
val model = AIOnDeviceModel(context)
if (model.isAvailable()) {
model.reply(instructions, turns).collect { answer -> show(answer) }
}Parameters
Any context; the application context is kept.
The longest answer, in tokens. The model writes at most MODEL_MAXIMUM_RESPONSE_TOKENS, so larger values are capped.
Types
Where the model is on this device.
Thrown by reply when the model can't answer on this device.
Functions
Downloads the model, when status is Status.Downloadable. The download continues while the flow is collected.
Whether the model can answer now.
Where the model is on this device. A device without AICore, or an error, reads as unavailable.