Repository navigation
Conversation
…isons Support FileOutput objects in encode_json and async_encode_json so they can be passed directly as inputs to downstream predictions without raising TypeError: Object of type FileOutput is not JSON serializable. Also implement __repr__, __eq__, and __hash__ on FileOutput for value-based comparison and logging. Signed-off-by: RealAdii <[email protected]>
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.
Fixes #377
Background & Issue Audit
KeyError: 'sample'intermittent failure on black-forest-labs/flux-2-pro predictions #453 (KeyError: 'sample'onblack-forest-labs/flux-2-pro): Confirmed that this is an upstream/server-side Replicate model hosting behavior rather than an SDK defect (replicate-pythoncontains no'sample'dictionary accesses anywhere in the codebase; 0 open PRs).replicate.run returning FileOutput objects).Summary of Changes
When
replicate.run(...)returnsFileOutputobjects, users frequently pass them into downstream predictions (e.g., image-to-image chaining) or perform equality checks against expected URLs in tests and pipeline logic. Previously:encode_json()andasync_encode_json()did not recognizeFileOutput, leaving the raw instance in the request dictionary and causinghttpxJSON serialization to fail withTypeError: Object of type FileOutput is not JSON serializable.FileOutputlacked a custom__eq__, causing equality comparisons (fo == "https://..."orfo1 == fo2) to evaluate toFalse(falling back to object identity).FileOutputlacked informative__repr__and__hash__implementations.Fix
encode_json()andasync_encode_json()inreplicate/helpers.pyto handleFileOutput:file_encoding_strategy == "base64": returns existing data URI or reads and base64-encodes the bytes.obj.urlas a standard string for JSON serialization.__repr__,__eq__(supporting comparisons against bothFileOutputinstances and string URLs), and__hash__onFileOutput.tests/test_helpers.pyfor equality, representation, hashing, and JSON encoding.tests/test_prediction.pyfor sync and async prediction creation withFileOutputinputs.Validation
pytest tests/: 163 passed, 6 skipped.ruff check: All checks passed.ruff format --check: All files formatted.