Skip to content

Conversation

@mattt
Copy link
Contributor

@mattt mattt commented Sep 12, 2024

This PR introduces a new WithFileOutput() option for a new RunWithOptions method in the Go client SDK. This option abstracts away file outputs from Replicate models, making it easier to work with file outputs and allowing for future optimizations in file asset delivery.

The new option can be used as follows:

output, err := client.RunWithOptions(ctx, "black-forest-labs/flux-schnell", input, nil, WithFileOutput())
reader, ok := output.(io.ReadCloser)
if ok {
    defer reader.Close()
    // Read from the reader
    data, err := io.ReadAll(reader)
    // Or stream the data
    _, err := io.Copy(destinationWriter, reader)
}

@mattt mattt requested a review from aron September 12, 2024 22:55
Copy link

@aron aron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks great, I wonder if we should mirror the Python/JS clients and return an interface that extends ReadCloser with a URL field so we can make the URL available too.

This way we can deprecate and remove the useFileOutput flag in future.

@mattt
Copy link
Contributor Author

mattt commented Sep 13, 2024

Nice! Looks great, I wonder if we should mirror the Python/JS clients and return an interface that extends ReadCloser with a URL field so we can make the URL available too.

Great idea! I just made that change.

@mattt mattt merged commit 696daff into main Sep 13, 2024
@mattt mattt deleted the mattt/file-output branch September 13, 2024 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants