feat: add backward compatibility for models.get("owner/name") syntax
#68
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 adds backward compatibility for the legacy
models.get("owner/name")syntax while maintaining full forward compatibility with the new keyword argument format.Changes
src/replicate/lib/models.pywith a clean patching system that handles both legacy and new syntaxReplicateandAsyncReplicateclasses to apply the compatibility patch when the models resource is createdmodels.get("stability-ai/stable-diffusion")models.get(model_owner="stability-ai", model_name="stable-diffusion")tests/test_models_backward_compat.pywith 12 test cases covering both syntax formats, async/sync clients, and error handlingapi_tokenparameter to both sync and asynccopy()methods to match__init__()signatureDetails
The code uses a simple patching approach (~115 lines total):
_parse_model_args()helper function handles both legacy "owner/name" and new keyword argument parsingpatch_models_resource()wraps the originalgetmethod with backward compatibility logicFixes Applied
bearer_tokeninstead of relying on environment mockingapi_tokenparameter tocopy()methods to prevent signature mismatch errorsTesting locally
gh repo clone replicate/replicate-python-stainless cd replicate-python-stainless gh pr checkout 68 scripts/test tests/test_models_backward_compat.pyResolves https://linear.app/replicate/issue/DP-656/add-backward-compatibility-for-modelsgetownername-syntax
Prompts