Introduce experimental FileOutput interface for models that output File and Path types#305
Merged
Introduce experimental FileOutput interface for models that output File and Path types#305
Conversation
This takes a url and creates a `ReadableStream` that has two additional methods `url()` and `blob()` for easily working with remote URLs or base64 encoded data.
This is currently behind the `useFileOutput` flag provided to the Replicate constructor. This allows us to test the feature before rolling it out more widely. When enabled any URLs or data-uris will be converted into a FileOutput type. This is essentially a `ReadableStream` that has two additional methods `url()` to return the underlying URL and `blob()` which will return a `Blob()` object 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.
Contributor
Author
|
@mattt thoughts on transforming |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
FileOutputtype to the client SDK to abstract away file outputs from Replicate models.It can be enabled by passing the
useFileOutputflag to the Replicate constructor.When enabled any URLs or data-uris will be converted into a FileOutput type. This is essentially a
ReadableStreamthat 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 theFileObjectto act like a URL string.