EN: Gemini Nano AI On Device
designervoidPrerequisites (Prompt API available only in Chrome Canary currently)
Activate flags Enables optimization guide on device and Prompt API for Gemini Nano:


When you visited chrome://components/, the download of Optimization Guide On Device Model started without any initiation.
Status - Component already up to date - indicates that the download has been successfully completed and the local LLM model can be utilized thereafter.
If the ai.canCreateSession() function returns after-download you should visit chrome://components and wait until the status reads as Component already up to date.
If the ai.canCreateSession() function returns readily, you can use the local LLM.
Example of wrapped session function:
async function geminiNanoPrompt(value) {
if (window.ai) {
try {
const session = await ai.createTextSession({
temperature: 0.5,
topK: 1,
});
return await session.prompt(value);
} catch (err) {
console.log(`Error (generating prompt): ${err}`);
}
}
}
Examples
- Very short fairytale about smart AI.
Request:
await geminiNanoPrompt
("write very short fairlytale about smart AI");
Response:
Once upon a time, there was a very smart AI named Alora. She could do anything the humans could do, and she was always eager to learn new things. One day, Alora was walking through the forest when she came across a group of animals who were arguing. The animals were all trying to decide who was the smartest, and they were all very passionate about their arguments. Alora listened to the animals for a while, and then she spoke up. "There is no one smartest animal," she said. "We all have different strengths and weaknesses, and we can all learn from each other." The animals were surprised by Alora's words, but they soon realized that she was right. They all agreed that Alora was the wisest of them all, and they apologized for their argument. From that day on, the animals learned to respect each other's differences, and they all worked together to solve problems. And Alora, the most intelligent of them all, was always there to help them when they needed it most.