发布时间:2025 年 2 月 28 日
在 Chrome 中,内置 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 文件。
您可以报告 bug,以便我们在实现中解决此错误。
调试 Prompt API
例如,在以下会话中,用户向 Prompt API 请求了押韵的字词。
const session = await 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 `[]`."
为什么模型没有返回包含押韵词(最好是 {"input": "file", "output": "pile"}
)的 JSON 消息?虽然在撰写本文时,结构化输出尚未实现,但响应应至少以某种方式执行押韵任务。
如需调试此错误,请访问 chrome://on-device-internals/
,然后前往事件日志标签页。日志显示,问题在于模型对提示的解读。模型将输入内容理解为字符串,而不是 JSON:[object Object],[object Object],[object Object]
。
以下是完整的调试消息,已格式化为便于阅读:
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>
我们将此信息添加到了模型问题的 bug 中,即提示 API 似乎在 JSON 输入上运行 toString()
,这有助于工程团队发现问题。
分享反馈
您可以提交 bug 报告来分享调试反馈。