Dereference OpenAPI schema returned by Function.openapi_schema#439
Merged
Dereference OpenAPI schema returned by Function.openapi_schema#439
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that Function.openapi_schema() and AsyncFunction.openapi_schema() return a fully dereferenced OpenAPI schema, honors version qualifiers in the model reference, and unifies the sync and async schema APIs.
- Introduces a
_dereference_schemahelper to inline$refentries undercomponents/schemas. - Converts the sync
openapi_schemafrom a property to a method (using a cached_openapi_schema) to match the async version. - Fixes version lookup so that a specific version in the model ref is returned (or latest if unspecified).
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/test_use.py | Added test_use_function_openapi_schema_dereferenced to verify inlined schemas and removal of unused definitions. |
| replicate/use.py | Added _dereference_schema, refactored/renamed openapi_schema logic for sync and async, and removed obsolete helpers. |
Comments suppressed due to low confidence (3)
replicate/use.py:62
- The removal of
_download_filelikely breaks_process_output_with_schema, which still references it for file downloads. Restoring this helper or refactoring the download logic would prevent a NameError when handling file-based outputs.
def _download_file(url: str) -> Path:
replicate/use.py:450
- There’s no test covering the new behavior when a version is explicitly specified in the ref string. Adding a test that uses
replicate.use("owner/model@v1.2.3")and asserts the correct schema is fetched would ensure this path stays validated.
_, _, model_version = self._parsed_ref
replicate/use.py:669
- [nitpick] The error message here differs from the sync variant (
has no latest version). Consider unifying these messages for consistency (e.g. alwayshas no latest version).
msg = f"Model {model.owner}/{model.name} has no version"
This commit also fixes the implementation to return the OpenAPI schema for the requested version rather than always the latest version.
9d72c7b to
7963a85
Compare
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 updates the
openapi_schemamethod inFunctionandAsyncFunctionto return a dereferenced API schema. This fixes a bug with transformation for models that output objects with named interfaces.This PR also introduces a breaking change in that
Function.openapi_schema()is now a method rather than a property to matchAsyncFunction.openapi_schema()the latter needs to be a method because the lookup of the version is both lazy and async.Lastly, the PR fixes an issue with the implementation where the latest OpenAPI schema was always returned. Now we return the version specified in the ref (or the latest if unspecified).