Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jeasonstudio committed Jun 21, 2024
1 parent 0d151c5 commit b394a75
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
72 changes: 54 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,69 @@

</div>

## Installation
> ⚠️ Note:
> * This module is under development and may contain errors and frequent incompatible changes.
> * Chrome's implementation of [built-in AI with Gemini Nano](https://developer.chrome.com/docs/ai/built-in) is an experiment and will change as they test and address feedback.
> * If you've never heard of it before, [follow these steps](#enable-ai-in-chrome) 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 i ai chrome-ai
npm install chrome-ai
```

## Enable AI in Chrome
## 🦄 Language Models

Chrome built-in AI is a preview feature, you need to use chrome version 127 or greater, now in [dev](https://www.google.com/chrome/dev/?extra=devchannel) or [canary](https://www.google.com/chrome/canary/) channel, [may release on stable chanel at Jul 17, 2024](https://chromestatus.com/roadmap), if release schedule on time.
The `chromeai` provider instance is a function that you can invoke to create a language model:

After then, you should turn on these flags:
* [chrome://flags/#prompt-api-for-gemini-nano](chrome://flags/#prompt-api-for-gemini-nano): `Enabled`
* [chrome://flags/#optimization-guide-on-device-model](chrome://flags/#optimization-guide-on-device-model): `Enabled BypassPrefRequirement`

Then click `Optimization Guide On Device Model` in [chrome://components/](chrome://components/) to download model.
```ts
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:

```ts
import { chromeai } from 'chrome-ai';

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

Finally, you can use prompt api in console, or use `chrome-ai` with `vercel/ai` to build projects.
You can use the following optional settings to customize:

## Usage
- **modelId** `'text' | 'generic'` (default: `'generic'`)
- **temperature** `number` (default: `0.8`)
- **topK** `number` (default: `3`)

generate text:
## 🎯 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('text'),
model: chromeai(),
prompt: 'Who are you?',
});

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

stream text:

```javascript
import { streamText } from 'ai';
import { chromeai } from 'chrome-ai';

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

Expand All @@ -92,7 +113,7 @@ console.log(result);
// I am a large language model, trained by Google.
```

generate object:
Chrome built-in language models can also be used in the generateObject function:

```javascript
import { generateObject } from 'ai';
Expand All @@ -118,4 +139,19 @@ const { object } = await generateObject({

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

> Due to model reasons, `toolCall` and `streamObject` are not supported. We are making an effort to implement these functions by prompt engineering.
## Enable AI in Chrome

Chrome built-in AI is a preview feature, you need to use chrome version 127 or greater, now in [dev](https://www.google.com/chrome/dev/?extra=devchannel) or [canary](https://www.google.com/chrome/canary/) channel, [may release on stable chanel at Jul 17, 2024](https://chromestatus.com/roadmap).

After then, you should turn on these flags:
* [chrome://flags/#prompt-api-for-gemini-nano](chrome://flags/#prompt-api-for-gemini-nano): `Enabled`
* [chrome://flags/#optimization-guide-on-device-model](chrome://flags/#optimization-guide-on-device-model): `Enabled BypassPrefRequirement`
* [chrome://components/](chrome://components/): Click `Optimization Guide On Device Model` to download the model.

## License

[MIT](LICENSE) License © 2024 [Jeason](https://github.com/jeasonstudio)
36 changes: 0 additions & 36 deletions example/index.html

This file was deleted.

0 comments on commit b394a75

Please sign in to comment.