Introduce experimental FileOutput interface for models that output File and Path types #305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a proposal to add a new
FileOutput
type to the client SDK to abstract away file outputs from Replicate models.It can be enabled by passing the
useFileOutput
flag to the Replicate constructor.When enabled any URLs or data-uris will be converted into a FileOutput type. This is essentially a
ReadableStream
that has two additional methodsurl()
to return the underlying URL andblob()
which will return aBlob()
instance with the file data loaded into memory.The intention here is to make it easier to work with file outputs and allows us to optimize the delivery of file assets to the client in future iterations.
Usage is as follows:
For most basic cases you'll want to utilize either the
url()
orblob()
methods depending on whether you want to directly consume the file or pass it on.To access the file URL:
To consume the file directly:
Or for very large files they can be streamed:
Or passed on to methods that support
ReadableStream
.An effort has been made to maintain backwards compatibility by implementing a
toString()
method which should cause theFileObject
to act like a URL string.