Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RunWithOptions method that supports returning file output as io.ReadCloser #77

Merged
merged 4 commits into from
Sep 13, 2024

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
3 checks passed
@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.

2 participants