Getting started

Using AiBrow from a webpage

AiBrow embeds itself into all pages using the window.aibrow namespace. If the browser doesn't support on-device AI, AiBrow will also polyfill the relevant APIs (i.e window.LanguageModel ). Check out our developer docs on how to get started!

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')
}

Typescript types

Types for window.aibrow can be added to your project by using the npm install --save-dev @aibrow/dom-types package. Then, to expose them, place the following either in your global.d.ts or the entry point to your code

import type AI from "@aibrow/dom-types"

declare global {
  interface Window {
    readonly aibrow: typeof AI;
  }
}

Using AiBrow from another extension

Install the library using npm install @aibrow/extension

import aibrow from '@aibrow/extension'

const { helper, extension } = await aibrow.capabilities()
if (extension) {
  if (helper) {
    const session = await 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')
}

Last updated