[小技巧] chrome开启本地模型local ai - gemini nano
date
Jan 21, 2025
slug
tip-chrome-local-gemini-nano-ai
status
Published
summary
小技巧
tags
tip
type
Post
URL
Problem & SummarySolution下载Dev版本Enable Gemini Nano and the Prompt APIBypassPerfRequirement下载模型Confirm availability of Gemini NanoTestcheck model download: if “Uncaught NotSupportedError: The model attempted to output text in an untested language, and was prevented from doing so.”
Problem & Summary
- chrome://flags/#prompt-api-for-gemini-nano

Solution
下载Dev版本
Enable Gemini Nano and the Prompt API
Follow these steps to enable Gemini Nano and the Prompt API flags for local experimentation:
- Go to chrome://flags/#prompt-api-for-gemini-nano
- Select Enabled
- Relaunch Chrome.
BypassPerfRequirement
chrome://flags/#optimization-guide-on-device-model
选择 Enabled BypassPerfRequirement
下载模型
DevTools console:
allow pasting
await window.ai.createTextSession()
await ai.summarizer.create();
await ai.summarizer.capabilities();
# check
(await ai.languageModel.capabilities()).available;

Confirm availability of Gemini Nano
- Open DevTools and send (await ai.languageModel.capabilities()).available; in the console.
If this returns “readily”, then you are all set.
Test

- in devtools console:
const canSummarize = await ai.summarizer.capabilities();
let summarizer;
if (canSummarize && canSummarize.available !== 'no') {
if (canSummarize.available === 'readily') {
// The summarizer can immediately be used.
summarizer = await ai.summarizer.create();
} else {
// The summarizer can be used after the model download.
summarizer = await ai.summarizer.create();
summarizer.addEventListener('downloadprogress', (e) => {
console.log(e.loaded, e.total);
});
await summarizer.ready;
}
} else {
// The summarizer can't be used at all.
}
check model download:
chrome://components/

if “Uncaught NotSupportedError: The model attempted to output text in an untested language, and was prevented from doing so.”
disable: chrome://flags/#text-safety-classifier