Introduction to Chrome AI
Chrome AI is an exciting project that integrates artificial intelligence into the Chrome browser through the Gemini Nano model. Developed as an experimental feature by Google, it provides a platform to explore AI capabilities directly within a web browser setting. Chrome AI leverages the Vercel AI SDK, offering a suite of functionalities that enhance web-based AI interactions.
Installation
Chrome AI is easily accessible through the chrome-ai
module. Installation is straightforward and can be achieved via npm with the following command:
npm install chrome-ai
Language Models
Chrome AI offers the ability to create language models using its intuitive interface. The chromeai
function serves as an entry point to access these models, enabling users to generate and customize AI responses.
import { chromeai } from 'chrome-ai';
const model = chromeai('text', {
temperature: 0.5,
topK: 5,
});
This allows developers to specify various configuration settings such as temperature and topK to fine-tune the AI's response behavior.
Embedding Models
Embedding models is another powerful feature of Chrome AI. Users can generate embeddings for various inputs and calculate their cosine similarities, which is useful for determining the relational closeness of data entries.
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'],
});
const similarity = cosineSimilarity(embeddings[0], embeddings[1]);
Examples
Chrome AI supports the generation of text and objects. Developers can utilize functions like generateText
or streamText
to produce AI-driven responses.
import { generateText } from 'ai';
import { chromeai } from 'chrome-ai';
const { text } = await generateText({
model: chromeai(),
prompt: 'Who are you?',
});
In addition, the module supports complex data constructs, allowing users to define schemas for generating structured data outputs:
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.',
});
Enabling AI in Chrome
Currently, Chrome's built-in AI is available on Chrome version 127 or newer, specifically in development channels like dev or canary. Users need to enable specific flags in their browser settings to activate AI features.
Alternatively, there's an experimental feature called chrome-ai/polyfill
that lets users simulate Chrome AI experiences in any modern browser supporting WebGPU and WebAssembly, further broadening accessibility.
import 'chrome-ai/polyfill';
License
The Chrome AI project operates under the MIT License, allowing developers to freely use, modify, and distribute the software within the terms of this licensing agreement.
In summary, Chrome AI opens new paths for AI integration within web environments, enabling versatile language and data processing directly through a browser interface. Its development is ongoing, with features continually evolving based on user feedback and technological advancements.