Add support for Pydantic 2 (#1858)
* Update pydantic and fastapi requirements
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Define PYDANTIC_V2
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Replace use of ErrorWrapper removed in pydantic v2
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Update predictor model config and output types
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Pass string literal for extra value
* Set explicit None values for optional fields
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Give output field an explicit default of None
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Import types from typing instead of accessing through namespace
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Set extra in model config
Set default description for enumerations
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Actually, don't allow additional properties
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Fix generated schema for webhook event filter
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Fixup generated OpenAPI schema
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Update expectations for test_gt_lt response JSON
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Flatten allOf for component schemas
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Fix validation of weights_url
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Use __get_pydantic_json_schema__ instead of __modify_schema__
* Fix test_make_encodeable_ignores_files
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Fix expectations for test_bad_int_input
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Skip numpy tests for pydantic v2
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Fix test_make_encodeable_encodes_pydantic_models for pydantic v2
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
* Fix use of __get_pydantic_core_schema__
* Fix warnings for pydantic.Field construction
* Fix use of deprecated dict instead of model_dump
* Limit application of OpenAPI processing for default enum description
* Passing test_openapi_specification_with_int_choices
* Fix declarations of __get_pydantic_json_schema__ and __get_pydantic_core_schema__
* Update validate_input_type to handle annotated cog.Types
* Update __get_pydantic_core_schema__ to start with is_instance_schema
* Conditionalize use of deprecated dict method
* Avoid re-encoding of PredictionResponse in _predict
* Remove no-op if TYPE_CHECKING
* Unwrap SerializationIterators after model_dump
* Also unwrap SerializationIterator in make_encodeable
* Replace use of choices=[] with typing.Literal
* Make output schema optional so validation doesn't fail on errors
* Restore choices tests and fix validation of choices in v2
* Refactor, move, and rename unwrap_pydantic_serialization_iterators to helpers module
* Update AST OpenAPI generator to support Literal
* Fix ast.Str and ast.Num deprecation warnings
* Disable Literal support for Python 3.8
* Apply suggestions from code review
Co-authored-by: Nick Stenning <nick@whiteink.com>
Signed-off-by: Mattt <mattt@me.com>
* Document unwrap_pydantic_serialization_iterators
* Test on Pydantic v1 and v2
Adds a Pydantic axis to the test matrix
* Fix import of Literal for Python 3.7
* Reenable and fix test_numpy
* Customize openapi_schema for Pydantic v1 and v2 to get consistent spec version of 3.1.0
Extract openapi manipulation functions to helpers
* Conditionalize call to unwrap_pydantic_serialization_iterators
* Correctly unset title for webhook_events_filter
* Skip literal tests for Python<3.9 and Pydantic<2
* Remove pyupgrade checks for ruff
* Fix pyright warning in useragent
* Manually remove webhook_events_filter title from OpenAPI schema
* Add support for Literal to Python <=3.9
* Run typecheck with Pydantic v1 and Pydantic v2
* Replace use of deprecated dict method with model_dump
* Attempt to resolve test failures related to OpenAPI generation
* Fix pydantic{1,2} typecheck
Copy the code to {envtmpdir} for pydantic1, since there's no way
to override pyright configuration temporarily.
* Fix type errors on pydantic1
* Install pydantic<2 in the cog wheel installation step.
Installing pydantic>2 won't easily downgrade when the user packages
require it, but upgrading works fine.
---------
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Signed-off-by: Mattt <mattt@me.com>
Signed-off-by: Morgan Fainberg <code@tempusfrang.it>
Co-authored-by: Yorick van Pelt <yorick@yorickvanpelt.nl>
Co-authored-by: Nick Stenning <nick@whiteink.com>
Co-authored-by: Morgan Fainberg <code@tempusfrang.it>