Skip to content

v1.4.0

Latest

Choose a tag to compare

@aron aron released this 17 Nov 11:17
· 1 commit to main since this release

This is a bug-fix release that fixes the behavior of replicate.stream() when dealing with models that output files. By default the event.data will be a FileOutput instance that can be written to disk.

import Replicate from "replicate";
import * as fs from "node:fs/promises";

const replicate = new Replicate();
const input = {
  prompt: "black forest gateau cake spelling out the words \"FLUX SCHNELL\", tasty, food photography, dynamic shot"
};

let index = 0;
for await (const event of replicate.stream("black-forest-labs/flux-schnell", { input })) {
  if (event.event === "output") {
      await fs.writeFile(`my-image-${index++}.png`, event.data);
  }
}

The stream() method also now supports the useFileOutput option which, when false, will output the HTTP or data URL directly.

import Replicate from "replicate";
const replicate = new Replicate();

const input = {
  prompt: "black forest gateau cake spelling out the words \"FLUX SCHNELL\", tasty, food photography, dynamic shot"
};

let index = 0;
for await (const event of replicate.stream("black-forest-labs/flux-schnell", { input, useFileOutput: false })) {
  if (event.event === "output") {
     console.log("URL:", event.data);
  }
}

What's Changed

  • Fix url key of createFileOutput options for streaming by @sitatec in #350

New Contributors

Full Changelog: v1.3.1...v1.4.0