百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

chrome-ai

> AI 编程
开源

Vercel Chrome 内置模型的 AI 提供程序 (Gemini Nano)

376 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

Vercel Chrome 内置模型的 AI 提供程序 (Gemini Nano)

⚠️ Note:

  • This module is under development and may contain errors and frequent incompatible changes.
  • Chrome's implementation of built-in AI with Gemini Nano is an experiment and will change as they test and address feedback.
  • If you've never heard of it before, follow these steps to turn on Chrome's built-in AI.

Installation

The ChromeAI provider is available in the chrome-ai module. You can install it with:

bash
npm install chrome-ai

Language Models

The chromeai provider instance is a function that you can invoke to create a language model:

typescript
import { chromeai } from 'chrome-ai';

const model = chromeai();

It automatically selects the correct model id. You can also pass additional settings in the second argument:

typescript
import { chromeai } from 'chrome-ai';

const model = chromeai('text', {
  // additional settings
  temperature: 0.5,
  topK: 5,
});

You can use the following optional settings to customize:

  • modelId 'text' (default: 'text'`)
  • temperature number (default: 0.8)
  • topK number (default: 3)

⭐️ Embedding models

typescript
import { chromeai } from 'chrome-ai';
import { embedMany, cosineSimilarity } from 'ai';

const { embeddings } = await embedMany({
  model: chromeai('embedding'),
  values: ['sunny day at the beach', 'rainy afternoon in the city'],
});
// [[1.9545, 0.0318...], [1.8015, 0.1504...]]

const similarity = cosineSimilarity(embeddings[0], embeddings[1]);
// similarity: 0.9474937159037822

Examples

You can use Chrome built-in language models to generate text with the generateText or streamText function:

javascript
import { generateText } from 'ai';
import { chromeai } from 'chrome-ai';

const { text } = await generateText({
  model: chromeai(),
  prompt: 'Who are you?',
});

console.log(text); //  I am a large language model, trained by Google.
javascript
import { streamText } from 'ai';
import { chromeai } from 'chrome-ai';

const { textStream } = await streamText({
  model: chromeai(),
  prompt: 'Who are you?',
});

let result = '';
for await (const textPart of textStream) {
  result += textPart;
}

console.log(result);
//  I am a large language model, trained by Google.

Chrome built-in language models can also be used in the generateObject/streamObject function:

javascript
import { generateObject } from 'ai';
import { chromeai } from 'chrome-ai';
import { z } from 'zod';

const { object } = await generateObject({
  model: chromeai(),
  schema: z.object({
    recipe: z.object({
      name: z.string(),
      ingredients: z.array(
        z.object({
          name: z.string(),
          amount: z.string(),
        })
      ),
      steps: z.array(z.string()),
    }),
  }),
  prompt: 'Generate a lasagna recipe.',
});

console.log(object);
// { recipe: {...} }
…

Due to model reasons, toolCall/functionCall are not supported. We are making an effort to implement these functions by prompt engineering.

Enabling AI in Chrome

Chrome built-in AI is a preview feature, you need to use chrome version 127 or greater, now in dev or canary channel, may release on stable chanel at Jul 17, 2024.

After then, you should turn on these flags:

  • chrome://flags/#prompt-api-for-gemini-nano: Enabled
  • chrome://flags/#optimization-guide-on-device-model: Enabled BypassPrefRequirement
  • chrome://components/: Click Optimization Guide On Device Model to download the model.

Or you can try using the experimental feature: chrome-ai/polyfill, to use chrome-ai in any browser that supports WebGPU and WebAssembly.

typescript
import 'chrome-ai/polyfill';
// or
require('chrome-ai/polyfill');

Star History

License

MIT License © 2024 Jeason

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptchromegeminigemini-nanollm

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.