發布日期:2025 年 9 月 4 日
說明 | 網頁 | 擴充功能 | Chrome 狀態 | 意圖 |
---|---|---|---|---|
GitHub | 查看 | Intent to Prototype |
校對是指尋找並修正文法、拼字和標點符號錯誤的過程。瀏覽器和作業系統越來越常為撰寫工具提供校對功能,例如 Google 文件。
透過 Proofreader API,您可以為網頁應用程式或擴充功能提供內建 AI 的互動式校對功能。這個 API 提供下列功能:
- 修正:修正使用者輸入的文法、拼字和標點符號。
- 標籤:根據錯誤類型為每項修正內容加上標籤。
- 說明:以簡單易懂的語言定義錯誤或說明為何需要修正。
用途
您可能會基於許多原因而想使用 Proofreader API,例如:
- 在提交論壇訊息、文章留言和電子郵件前,建議修正內容。
- 在錄音期間提供修正內容。
找不到適合的用途嗎?加入搶先體驗計畫,分享您的意見。
開始使用
加入 Proofreader API 來源試用,這項試用活動將在 Chrome 141 至 145 版進行。
查看硬體需求
開發人員和在 Chrome 中使用這些 API 操作功能的使用者,都必須遵守下列規定。其他瀏覽器的操作規定可能不同。
語言偵測器和翻譯器 API 適用於電腦版 Chrome。這些 API 不適用於行動裝置。在 Chrome 中,只要符合下列條件,即可使用 Prompt API、Summarizer API、Writer API、Rewriter API 和 Proofreader API:
- 作業系統:Windows 10 或 11;macOS 13 以上版本 (Ventura 以上版本); Linux;或 Chromebook Plus 裝置上的 ChromeOS (自 Platform 16389.0.0 以上版本)。 使用 Gemini Nano 的 API 目前不支援 Android 版、iOS 版 Chrome,以及非 Chromebook Plus 裝置上的 ChromeOS。
- 儲存空間:包含 Chrome 設定檔的磁碟區至少要有 22 GB 的可用空間。
- GPU:視訊記憶體必須超過 4 GB。
- 網路:無限量數據或不計量的連線。
瀏覽器更新模型時,Gemini Nano 的確切大小可能會有所不同。如要瞭解目前的容量,請前往 chrome://on-device-internals
。
新增對 localhost 的支援
如要在來源試用期間透過 localhost 存取 Proofreader API,請務必更新 Chrome 至最新版本。接下來,請按照下列步驟進行:
- 前往
chrome://flags/#proofreader-api-for-gemini-nano
。 - 選取「已啟用」。
- 按一下「重新啟動」或重新啟動 Chrome。
申請加入來源試用計畫
如要開始使用 Proofreader API,請按照下列步驟操作:
- 確認瞭解《Google 生成式 AI 使用限制政策》。
- 前往 Proofreader API 來源試用。
- 按一下「註冊」並填寫表單。在「網站來源」欄位中,提供來源或擴充功能 ID,
chrome-extension://YOUR_EXTENSION_ID
。 - 按一下「註冊」即可提交。
- 複製系統提供的權杖,並加到來源的每個參與網頁,或加入擴充功能資訊清單。
- 如果您要建構擴充功能,請按照擴充功能原始試用操作說明操作
- 開始使用 Proofreader API。
進一步瞭解如何開始使用來源試用計畫。
使用 Proofreader API
如要判斷模型是否可供使用,請呼叫 Proofreader.availability()。如果 availability()
的回應為 "downloadable"
,請監聽下載進度並通知使用者,因為下載可能需要一段時間。
const options = {
expectedInputLanguages: ['en'],
};
const available = if (Proofreader.availability("downloadable") === true);
如要觸發下載並例項化校對工具,請檢查使用者啟用狀態。然後呼叫非同步 Proofreader.create()
函式。
const session = await Proofreader.create({
monitor(m) {
m.addEventListener('downloadprogress', (e) => {
console.log(`Downloaded ${e.loaded * 100}%`);
});
},
...options,
});
建立 Proofreader 物件
如要建立校對工具,請使用 Proofreader.create()
函式。
const proofreader = await Proofreader.create({
expectedInputLanguages: ["en"],
monitor(m) {
m.addEventListener("downloadprogress", e => {
console.log(Downloaded ${e.loaded * 100}%);
});
}
};
create()
方法包含下列選項:
expectedInputLanguages
:預期輸入語言的陣列。
系統不支援說明中的 includeCorrectionTypes
和 includeCorrectionExplanation
選項。
開始校對使用者文字
呼叫 proofread()
即可取得輸入文字的修正內容:
const proofreadResult = await proofreader.proofread(
'I seen him yesterday at the store, and he bought two loafs of bread.',
);
修正內容屬於 ProofreadResult
類型。在 corrected
屬性中找出完全修正的輸入內容,並在 corrections
陣列中找出修正內容清單:
let inputRenderIndex = 0;
console.log(proofreadResult.correction);
for (const correction of proofreadResult.corrections) {
// Render part of input that has no error.
if (correction.startIndex > inputRenderIndex) {
const unchangedInput = document.createElement('span');
unchangedInput.textContent = input.substring(inputRenderIndex, correction.startIndex);
editBox.append(unchangedInput);
}
// Render part of input that has an error and highlight as such.
const errorInput = document.createElement('span');
errorInput.textContent = input.substring(correction.startIndex, correction.endIndex);
errorInput.classList.add('error');
editBox.append(errorInput);
inputRenderIndex = correction.endIndex;
}
// Render the rest of the input that has no error.
if (inputRenderIndex !== input.length){
const unchangedInput = document.createElement('span');
unchangedInput.textContent = input.substring(inputRenderIndex, input.length);
editBox.append(unchangedInput);
}
權限政策、iframe 和 Web Worker
根據預設,校對工具 API 僅適用於頂層視窗,以及同源 iframe。您可以使用 Permission Policy allow="" 屬性,將 API 存取權委派給跨來源 iframe:
<!--
The hosting site at https://main.example.com can grant a cross-origin iframe
at https://cross-origin.example.com/ access to the Proofreader API by
setting the `allow="proofreader"` attribute.
-->
<iframe src="https://cross-origin.example.com/" allow="proofreader"></iframe>
Web Worker 不支援 Proofreader API。這是因為要為每位工作人員建立負責文件,以檢查權限政策狀態,相當複雜。
示範
在校對工具 API 遊樂場中試用。
參與討論及分享意見
Proofreader API 目前仍在討論階段,日後可能會有變動。如果您試用過這項 API,歡迎提供意見。
- 閱讀說明、提出問題並參與討論。
- 在 Chrome 狀態中查看 Chrome 的實作方式
- 請參閱 Mozilla 標準立場和 WebKit 標準立場。
- 加入搶先體驗計畫,提前瞭解新 API 並加入我們的郵寄清單。
- 如要對 Chrome 的實作方式提供意見,請回報 Chromium 錯誤。
在瀏覽器中探索所有內建 AI API,這些 API 使用模型 (包括大型語言模型)。