Get started on the web

AiBrow embeds itself into all pages using the window.aibrow namespace (also window.ai is polyfilled if it's not available natively in the browser). 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;
  }
}

Last updated