node-replicate
A NodeJS 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)
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, Midjourney and other cutting-edge models witih just a few lines of code 😊👌.
Features
- Run Replicate models anonymously 👻.
- Track pending predictions ⌛.
- Very lightweight - under 100 lines of code ⚡.
Installation
Install with npm.
npm i node-replicate
Usage
To run a Replicate model, pass its identifier to replicate.model() and then invoke predict() asynchronously.
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)
You can also track a pending predictions by passing an onUpdate() callback.
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)
Contributing
Have a feature you'd like to see added? Create a pull request or open an issue. Some planned features include support for file uploads and integration with the authenticated Replicate API.