JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 148
  • Score
    100M100P100Q75503F
  • License MIT

A Node.js client for Replicate.

Package Exports

  • node-replicate
  • node-replicate/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-replicate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-replicate

A Node.js client for Replicate.

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
   )
  .predict({
    prompt: "an astronaut riding on a horse",
  })

console.log(prediction.output)

// [ "https://replicate.delivery/pbxt/f4nlztv3uz1iFC4AEf2wBYQGTezdVeysvtZUtwfsvZOJDN6AC/out-0.png" ]

Introduction

Replicate is an online platform for running machine learning models in the cloud. This package implements a lightweight client for their anonymous API, allowing you to run Stable Diffusion, Whisper and other cutting-edge models in just a few lines of code 😄🤏.

Features

  • Run models anonymously 👻.
  • Monitor pending predictions 😴.
  • Lightweight - under 100 lines of code 🔥.

Installation

Install with npm.

npm i node-replicate

Usage

To run a model, just pass its identifier to replicate.model() and then call predict(). You can find its identifier and prediction parameters on Replicate (e.g. https://replicate.com/stability-ai/stable-diffusion/api).

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
   )
  .predict({
    prompt: "an astronaut riding on a horse",
  })

console.log(prediction.output)

// [ "https://replicate.delivery/pbxt/f4nlztv3uz1iFC4AEf2wBYQGTezdVeysvtZUtwfsvZOJDN6AC/out-0.png" ]

You can also monitor pending predictions with onUpdate().

import replicate from "node-replicate"

const prediction = await replicate
  .model(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
   )
  .predict(
    {
      prompt: "an astronaut riding on a horse",
    },
    {
      onUpdate(prediction) {
        console.log(prediction.status)
      },
    },
  )

console.log(prediction.output)

// [ "https://replicate.delivery/pbxt/f4nlztv3uz1iFC4AEf2wBYQGTezdVeysvtZUtwfsvZOJDN6AC/out-0.png" ]

Contributing

Have a feature you'd like to see included? Create a pull request or open an issue.