Skip to content

Commit

Permalink
Add code examples to the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas101 committed Oct 25, 2024
1 parent d77beca commit ef05673
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The development API follows the current proposal for the browser [Prompt API](ht
The extension works on all Chromium based browsers as well as Firefox.

* [Docs](https://docs.aibrow.ai/)
* [API Reference](https://docs.aibrow.ai/api-reference/aibrow)
* [Playground](https://demo.aibrow.ai/playground/)

## How can I try AiBrow?
Expand All @@ -25,9 +26,51 @@ The easiest way is to download through the Chrome Web Store or Mozilla add-on st
3. Click the `Load temporary Add-on`
4. [Try out the playground](https://demo.aibrow.ai/playground/)

## How can I use AiBrow in my site/extension?

AiBrow embeds itself to the page using the `window.aibrow` namespace. Check out our [developer docs](https://docs.aibrow.ai/) on how to get started!
## How can I use the AiBrow API?

### Website

AiBrow embeds itself to the page using the `window.aibrow` namespace (also `window.ai` if it's not already available). Check out our [developer docs](https://docs.aibrow.ai/) on how to get started!

```js
if (window.aibrow) {
const { helper } = await window.aibrow.capabilities()
if (helper) {
const session = await window.aibrow.languageModel.create()
const stream = await sess.promptStreaming('Write a poem about AI in the browser')
for await (const chunk of stream) {
console.log(chunk)
}
} else {
console.log('Aibrow helper not installed')
}
} else {
console.log('Aibrow not installed')
}
```

### Extension

Install the library using `npm install @aibrow/extension`

```js
import aibrow from '@aibrow/extension'

const { helper, extension } = await window.aibrow.capabilities()
if (extension) {
if (helper) {
const session = await window.aibrow.languageModel.create()
const stream = await sess.promptStreaming('Write a poem about AI in the browser')
for await (const chunk of stream) {
console.log(chunk)
}
} else {
console.log('Aibrow helper not installed')
}
} else {
console.log('Aibrow not installed')
}
```

## How can I build AiBrow myself?

Expand Down

0 comments on commit ef05673

Please sign in to comment.