GuidesRecipes
DiscordDashboard
DiscordDashboard

Javascript

NOTE:

If you're using React, we recommend to use the usePolyfire hook

With NPM

First install the Polyfire SDK:

npm install polyfire-js

Import the PolyfireClientBuilder object

import PolyfireClientBuilder from "polyfire-js";

Without NPM

You can initialize Polyfire by importing the browser minified script:

<script src="https://github.com/polyfire-ai/polyfire-js/releases/download/0.2.7/polyfire-min-0.2.7.js"></script>

The PolyfireClientBuilder object is added as a global variable in the window object

Using the polyfire Object

You can check if the user is already connected by using the polyfire.auth.init() function

If they aren't we'll have to use the polyfire.auth.login(provider: string) method to connect them first

const polyfire = PolyfireClientBuilder({ project: "your_project_alias" })

const isAuthenticated = await polyfire.auth.init();
if (!isAuthenticated) {
  await polyfire.auth.login("github")
}

const helloWorld = await polyfire.models.generate("Write me a hello world haiku");
console.log(helloWorld);