快速體驗一下 Chrome 內建的 AI

什麼是 Chrome AI?

最新的 Chrome 測試版瀏覽器內建了一款名為 Gemini Nano 的 AI 模型。這是最新的 Gemini 系列中最輕量的版本,專為在使用者設備上運行而設計。由於是較小的 AI 模型,它不需要依賴遠端伺服器進行運算,這表示資料不會離開你的設備,能夠更好地保護使用者的隱私。

設定 Chrome AI

  1. 下載最新版 Chrome:

  2. 啟用 AI 功能:

    • 在 Chrome 瀏覽器中,在網址上輸入: chrome://flags/
    • 找到 “Prompt API for Gemini Nano”, 將其設定為 “Enabled”
    • 找到 “Enables optimization guide on device”, 將其設定為 “Enabled BypassPerfRequirement”
    • 點擊頁面底部的 “Restart” 按鈕重啟瀏覽器
    • Console 下輸入 await window.ai.createTextSession()。(為了要觸發下載模型的選項,這裡有錯誤是正常的)
  3. 下載 AI 模型:

    • 在網址上輸入: chrome://components/
    • 找到 “Optimization Guide On Device Model”
    • 按下 “Check for update” 按鈕
    • 等待下載完成

使用 Chrome AI

  1. 開啟 Console
  2. 複製並貼上以下代碼
1
2
3
4
5
6
7
8
async function askAI(question) {
const session = await window.ai.createTextSession();
const answer = await session.prompt(question);
console.log(answer);
session.destroy();
}

askAI("Tell me a joke");
1
2
3
4
5
6
7
8
9
10
11
async function askAIWithStreaming(question){
const session = await window.ai.createTextSession();
const stream = session.promptStreaming(question);
for await (const chunk of stream){
console.log(chunk)
}
session.destroy();
console.log('done');
}

askAIWithStreaming("Summarize in English, concise and clear. Article:" + document.querySelector("article").innerText);

心得

目前使用下來效果不佳,可能是因為還在測試階段,使用的模型較小,或者我下達 Prompt 的方式不正確。連很常用的總結文章也出現了很多奇怪的內容。之後會再等正式版釋出後繼續觀察。