-
Notifications
You must be signed in to change notification settings - Fork 982
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
fix: compatibility with pydantic v2 #3273
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
from typing import Optional, List, Union, Dict | ||
|
||
import orjson | ||
from pydantic import BaseModel | ||
from pydantic import BaseModel, ConfigDict | ||
|
||
# TODO: in the future, this file can be auto generated | ||
# https://pydantic-docs.helpmanual.io/datamodel_code_generator/ | ||
|
@@ -102,7 +102,7 @@ class ModelMetadataResponse(BaseModel): | |
} | ||
""" | ||
name: str | ||
versions: Optional[List[str]] | ||
versions: Optional[List[str]] = None | ||
platform: str | ||
inputs: List[MetadataTensor] | ||
outputs: List[MetadataTensor] | ||
|
@@ -136,7 +136,7 @@ class RequestInput(BaseModel): | |
name: str | ||
shape: List[int] | ||
datatype: str | ||
parameters: Optional[Parameters] | ||
parameters: Optional[Parameters] = None | ||
data: List | ||
|
||
|
||
|
@@ -150,7 +150,7 @@ class RequestOutput(BaseModel): | |
} | ||
""" | ||
name: str | ||
parameters: Optional[Parameters] | ||
parameters: Optional[Parameters] = None | ||
|
||
|
||
class ResponseOutput(BaseModel): | ||
|
@@ -168,7 +168,7 @@ class ResponseOutput(BaseModel): | |
name: str | ||
shape: List[int] | ||
datatype: str | ||
parameters: Optional[Parameters] | ||
parameters: Optional[Parameters] = None | ||
data: List | ||
|
||
|
||
|
@@ -183,7 +183,7 @@ class InferenceRequest(BaseModel): | |
"outputs" : [ $request_output, ... ] #optional | ||
} | ||
""" | ||
id: Optional[str] | ||
id: Optional[str] = None | ||
parameters: Optional[Parameters] = None | ||
inputs: List[RequestInput] | ||
outputs: Optional[List[RequestOutput]] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to replace Config with model_config if we want it to work in pydantic 2 |
||
|
@@ -229,10 +229,11 @@ class InferenceResponse(BaseModel): | |
} | ||
""" | ||
model_name: str | ||
model_version: Optional[str] | ||
model_version: Optional[str] = None | ||
id: str | ||
parameters: Optional[Parameters] | ||
parameters: Optional[Parameters] = None | ||
outputs: List[ResponseOutput] | ||
model_config = ConfigDict(protected_namespaces='') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the new syntax for pydantic 2 that's analogous to the nested Config class in pydantic 1. My guess is that Pydantic2 uses "model_" a protected namespace which we need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to suppress this warning:
So it really ought to be an empty tuple. |
||
|
||
class Config: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pydantic 1 syntax. We should move the https://docs.pydantic.dev/latest/migration/#changes-to-config |
||
schema_extra = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we surround the imports with try-catch in for backwards compatibility purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do -- we should likely also likely add if/else for the the class definitions to switch from the nested Config class to model_config