Coder Social home page Coder Social logo

partnerise / polyfire-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from polyfire-ai/polyfire-js

0.0 0.0 0.0 8.66 MB

๐Ÿ”ฅ A managed backend for AI apps. Call AI models from the frontend

Home Page: https://www.npmjs.com/package/polyfact

JavaScript 60.47% TypeScript 39.53%

polyfire-js's Introduction

๐Ÿ”ฅ polyfire

โšก An all-in-one managed backend for AI apps. Build AI apps from the frontend, very fast. ๐Ÿชถ

Why use Polyfire?

  • Just code from the frontend, no backend needed
  • If you already have backend, less code to write
  • Most backend services you'd need in a couple lines of code

We manage your AI backend so you don't have to.

Demo Gif

๐Ÿงฐ Examples

We have several examples in our documentation. But here are two simple ones to get you started

React

import { useState, useEffect } from "react";
import { createRoot } from "react-dom/client";
import { PolyfireProvider, usePolyfire } from "polyfire-js/hooks";

function App() {
  const { auth: { login, status }, models: { generate } } = usePolyfire();
  const [haiku, setHaiku] = useState();

  useEffect(() => {
    if (status === "authenticated") generate("haiku").then(setHaiku);
  }, [status]);

  if (status === "unauthenticated")
    return <button onClick={() => login("github")}>Login with Github</button>;
  else if (status === "loading" || !haiku) return <h1>Loading...</h1>;
  return <h1>{haiku}</h1>;
}

document.body.innerHTML = '<div id="app"></div>';
const root = createRoot(document.getElementById("app"));
root.render(<PolyfireProvider project="your_project_id"><App /></PolyfireProvider>);

Don't forget to change the your_project_id by your project ID you will have got on https://beta.polyfire.com

Vanilla JS

<script src="https://github.com/polyfire-ai/polyfire-js/releases/download/0.2.7/polyfire-min-0.2.7.js"></script>
<script>
	(async () => {
		const polyfire = window.PolyfireClientBuilder({ project: "your_project_id" })
		
		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);
	})()
</script>

Don't forget to change the your_project_id by your project ID you will have got on https://beta.polyfire.com

๐Ÿ†• Getting Started

To get an overview of Polyfire follow this Basic Usage tutorial.

โœจ Starter Guides

We also made a couple of tutorials you can use to get started with Polyfire:

๐Ÿ“š Useful References

๐Ÿ”— Links

We're open source! Make a good PR to the JS SDK or the API and we'll merge it.

polyfire-js's People

Contributors

lowczarc avatar kevin-btc avatar victorforissier avatar chuongmep avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.