Stream HelpersReplicateStream
ReplicateStream
The ReplicateStream function is a utility that handles extracting the stream from the output of Replicate's API. It expects a Prediction object as returned by the Replicate JavaScript SDK, and returns a ReadableStream. Unlike other wrappers, ReplicateStream returns a Promise because it makes a fetch call to the Replicate streaming API under the hood.
Import
React
import { ReplicateStream } from "ai"
Parameters
pre:
Object returned by the Replicate JavaScript SDK.
callback?:
An object containing callback functions to handle the start, each token, and completion of the AI response. In the absence of this parameter, default behavior is implemented.
Returns
A ReadableStream wrapped in a promise.