發布日期:2025 年 2 月 28 日
內建 AI 會使用 Gemini Nano 為所有 API 執行推論。有時 Gemini Nano 可能會傳回錯誤訊息,或無法傳回預期的結果。您可以查看使用 Gemini Nano 的所有內建 AI API 的偵錯資訊。包括 Prompt API、Summarizer API、Writer API 和 Rewriter API。
- 開啟 Chrome 並前往
chrome://on-device-internals
。 - 選取「事件記錄」。
- (選用) 按一下「Dump」,即可下載包含所有事件資訊的 JSON 檔案。
您可以回報錯誤,我們會在實作中修正這項錯誤。
範例:對提示 API 進行偵錯
舉例來說,在下列工作階段中,使用者要求 Prompt API 提供押韻的字詞。
const session = await ai.languageModel.create({
systemPrompt: "You are an API endpoint that returns rhymes as JSON for an input word."
});
await session.prompt([
{ role: "user", content: "house" },
{ role: "assistant", content: "{\"input\": \"house\", \"output\": \"mouse\"}" },
{ role: "user", content: "file"},
]);
模型的回應如下,我們已調整格式以利閱讀:
```json
[]
```
**Reasoning:**
The input you provided (empty arrays) is an empty list or array in JSON format.
When you try to find rhymes for an empty list, you're essentially looking for
words that rhyme with nothing.
Therefore, there are no rhymes to return. The JSON response will be an empty
array `[]`."
為什麼模型沒有傳回含有押韻字詞的 JSON 訊息 (理想情況為 {"input": "file", "output": "pile"}
)?雖然結構化輸出內容在本文撰寫時尚未實作,但回應至少應以某種方式執行押韻任務。
如要對這個錯誤進行偵錯,請前往 chrome://on-device-internals/
並點選「Event Logs」分頁。記錄顯示問題出在模型對提示的解讀方式。模型將輸入內容解讀為字串 ([object Object],[object Object],[object Object]
),而非 JSON。
以下是完整的偵錯訊息,並以易讀格式呈現:
Executing model with input context of 0 tokens:
<system>You are an API endpoint that returns rhymes as JSON for an input word.<end>
with string: <user>[object Object],[object Object],[object Object]<end> <model>
我們已將這項資訊加入模型問題的錯誤,提示 API 似乎會在 JSON 輸入內容上執行 toString()
,這有助於工程團隊找出問題。
提供意見
如要提供偵錯意見,請提交錯誤報告。