+
95
-

回答

是的, chrome127内置了Gemini Nano 大语言模型,可以通过js调用

具体步骤如下:下载 Chrome 127 版本,可以通过访问 Chrome Release Channels 获取 Canary 版本,下载地址:https://www.chromium.org/getting-involved/dev-channel/

在浏览器地址栏中输入chrome://flags/,启用以下设置:

将Prompt API for Gemini Nano设置为Enable。

将Enables optimization guide on device设置为Enable BypassPerfR。 完成后重启 Chrome。

访问chrome://components/,检查Optimization Guide On Device Model是否已成功下载模型,如未下载,点击Check for update。

通过打开控制台并输入测试代码来验证 Gemini Nano 是否正常工作。测试代码如下:

const canCreate = await window.ai.canCreateGenericSession()

if (canCreate !== "no") {
    const session = await window.ai.createTextSession();
    const stream = session.promptStreaming("Tell me a joke!")
    for await (const chunk of stream) {
        console.log(chunk)
    }
    session.destroy()
} else {
    console.error(" can't create generic session", canCreate)
}

网友回复

我知道答案,我要回答