Skip to main content

在Chrome中内置端侧大模型

· 2 min read

最近Chrome在开发者预览版中发布了Built-in AI Early Preview Program, 这个功能能够让Chrome启用生成式AI, 这个功能目前处于预览阶段, 通过一些配置才可以启用, 以下是启用步骤:

启用步骤

  1. 打开https://www.google.com/chrome/dev/下载最新的Chrome Dev版本.
  2. 打开chrome://flags/#optimization-guide-on-device-model , 找到Enables optimization guide on device功能, 并配置为Enabled BypassPerfRequirement.
  3. 打开chrome://flags/#prompt-api-for-gemini-nano, 找到Prompt API for Gemini Nano功能, 配置为Enabled.
  4. 打开chrome://components/确认Optimization Guide On Device Model组件下载成功并且是最新版本.
  5. 打开console, 输入await window.ai.canCreateTextSession();, 如果返回值为readily, 那么说明已经启用了生成式AI.

试用

创建html文件, 并将以下内容复制到其中:

index.html
<!doctype html>
<html>

<head>
<meta charset="utf-8" />
<title>Marked in the browser</title>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</head>

<body>
</body>

</html>

打开F12, 赋值以下代码到Console中, prompt根据需求进行修改:

session = await window.ai.createTextSession();
for await (var res of session.promptStreaming`Give me typescript code about generic type`) { document.body.innerHTML = marked.parse(res) }

备注

由于该功能尚处于预览阶段, 随着迭代更新, 配置可能会发生变化, 请关注Chrome官方文档以获取最新配置信息.

参考资料