Skip to content

Commit 5d863ed

Browse files
Generate modelserving
1 parent 875e273 commit 5d863ed

19 files changed

Lines changed: 141 additions & 69 deletions

services/modelserving/oas_commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0e64886dd0847341800d7191ed193b75413be998
1+
8f43ed707da765654e4427642c9d978f80d504e1

services/modelserving/src/stackit/modelserving/api_client.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class ApiClient:
6767
"date": datetime.date,
6868
"datetime": datetime.datetime,
6969
"decimal": decimal.Decimal,
70+
"UUID": uuid.UUID,
7071
"object": object,
7172
}
7273
_pool = None
@@ -266,7 +267,7 @@ def response_deserialize(
266267
response_text = None
267268
return_data = None
268269
try:
269-
if response_type == "bytearray":
270+
if response_type in ("bytearray", "bytes"):
270271
return_data = response_data.data
271272
elif response_type == "file":
272273
return_data = self.__deserialize_file(response_data)
@@ -327,25 +328,20 @@ def sanitize_for_serialization(self, obj):
327328
return obj.isoformat()
328329
elif isinstance(obj, decimal.Decimal):
329330
return str(obj)
330-
331331
elif isinstance(obj, dict):
332-
obj_dict = obj
332+
return {key: self.sanitize_for_serialization(val) for key, val in obj.items()}
333+
334+
# Convert model obj to dict except
335+
# attributes `openapi_types`, `attribute_map`
336+
# and attributes which value is not None.
337+
# Convert attribute name to json key in
338+
# model definition for request.
339+
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
340+
obj_dict = obj.to_dict()
333341
else:
334-
# Convert model obj to dict except
335-
# attributes `openapi_types`, `attribute_map`
336-
# and attributes which value is not None.
337-
# Convert attribute name to json key in
338-
# model definition for request.
339-
if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009
340-
obj_dict = obj.to_dict()
341-
else:
342-
obj_dict = obj.__dict__
343-
344-
if isinstance(obj_dict, list):
345-
# here we handle instances that can either be a list or something else, and only became a real list by calling to_dict() # noqa: E501
346-
return self.sanitize_for_serialization(obj_dict)
342+
obj_dict = obj.__dict__
347343

348-
return {key: self.sanitize_for_serialization(val) for key, val in obj_dict.items()}
344+
return self.sanitize_for_serialization(obj_dict)
349345

350346
def deserialize(self, response_text: str, response_type: str, content_type: Optional[str]):
351347
"""Deserializes response into an object.
@@ -418,6 +414,8 @@ def __deserialize(self, data, klass):
418414
return self.__deserialize_datetime(data)
419415
elif klass is decimal.Decimal:
420416
return decimal.Decimal(data)
417+
elif klass is uuid.UUID:
418+
return uuid.UUID(data)
421419
elif issubclass(klass, Enum):
422420
return self.__deserialize_enum(data, klass)
423421
else:

services/modelserving/src/stackit/modelserving/models/chat_model_details.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from uuid import UUID
2222

2323
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
24+
from pydantic_core import to_jsonable_python
2425
from typing_extensions import Annotated, Self
2526

2627
from stackit.modelserving.models.sku import SKU
@@ -80,20 +81,29 @@ def category_validate_enum(cls, value):
8081
@field_validator("description")
8182
def description_validate_regular_expression(cls, value):
8283
"""Validates the regular expression"""
84+
if not isinstance(value, str):
85+
value = str(value)
86+
8387
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
8488
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
8589
return value
8690

8791
@field_validator("displayed_name")
8892
def displayed_name_validate_regular_expression(cls, value):
8993
"""Validates the regular expression"""
94+
if not isinstance(value, str):
95+
value = str(value)
96+
9097
if not re.match(r"^[0-9a-zA-Z\s_-]+$", value):
9198
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s_-]+$/")
9299
return value
93100

94101
@field_validator("name")
95102
def name_validate_regular_expression(cls, value):
96103
"""Validates the regular expression"""
104+
if not isinstance(value, str):
105+
value = str(value)
106+
97107
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
98108
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
99109
return value
@@ -111,12 +121,16 @@ def quantization_method_validate_enum(cls, value):
111121
@field_validator("url")
112122
def url_validate_regular_expression(cls, value):
113123
"""Validates the regular expression"""
124+
if not isinstance(value, str):
125+
value = str(value)
126+
114127
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
115128
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
116129
return value
117130

118131
model_config = ConfigDict(
119-
populate_by_name=True,
132+
validate_by_name=True,
133+
validate_by_alias=True,
120134
validate_assignment=True,
121135
protected_namespaces=(),
122136
)
@@ -127,8 +141,7 @@ def to_str(self) -> str:
127141

128142
def to_json(self) -> str:
129143
"""Returns the JSON representation of the model using alias"""
130-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
131-
return json.dumps(self.to_dict())
144+
return json.dumps(to_jsonable_python(self.to_dict()))
132145

133146
@classmethod
134147
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/create_token_payload.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Any, ClassVar, Dict, List, Optional, Set
2121

2222
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
23+
from pydantic_core import to_jsonable_python
2324
from typing_extensions import Annotated, Self
2425

2526

@@ -43,19 +44,26 @@ def description_validate_regular_expression(cls, value):
4344
if value is None:
4445
return value
4546

47+
if not isinstance(value, str):
48+
value = str(value)
49+
4650
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
4751
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
4852
return value
4953

5054
@field_validator("name")
5155
def name_validate_regular_expression(cls, value):
5256
"""Validates the regular expression"""
57+
if not isinstance(value, str):
58+
value = str(value)
59+
5360
if not re.match(r"^[0-9a-zA-Z\s_-]+$", value):
5461
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s_-]+$/")
5562
return value
5663

5764
model_config = ConfigDict(
58-
populate_by_name=True,
65+
validate_by_name=True,
66+
validate_by_alias=True,
5967
validate_assignment=True,
6068
protected_namespaces=(),
6169
)
@@ -66,8 +74,7 @@ def to_str(self) -> str:
6674

6775
def to_json(self) -> str:
6876
"""Returns the JSON representation of the model using alias"""
69-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
70-
return json.dumps(self.to_dict())
77+
return json.dumps(to_jsonable_python(self.to_dict()))
7178

7279
@classmethod
7380
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/create_token_response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, StrictStr
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Self
2324

2425
from stackit.modelserving.models.token_created import TokenCreated
@@ -34,7 +35,8 @@ class CreateTokenResponse(BaseModel):
3435
__properties: ClassVar[List[str]] = ["message", "token"]
3536

3637
model_config = ConfigDict(
37-
populate_by_name=True,
38+
validate_by_name=True,
39+
validate_by_alias=True,
3840
validate_assignment=True,
3941
protected_namespaces=(),
4042
)
@@ -45,8 +47,7 @@ def to_str(self) -> str:
4547

4648
def to_json(self) -> str:
4749
"""Returns the JSON representation of the model using alias"""
48-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49-
return json.dumps(self.to_dict())
50+
return json.dumps(to_jsonable_python(self.to_dict()))
5051

5152
@classmethod
5253
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/embedding_model_details.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from uuid import UUID
2222

2323
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
24+
from pydantic_core import to_jsonable_python
2425
from typing_extensions import Annotated, Self
2526

2627
from stackit.modelserving.models.sku import SKU
@@ -64,33 +65,46 @@ def category_validate_enum(cls, value):
6465
@field_validator("description")
6566
def description_validate_regular_expression(cls, value):
6667
"""Validates the regular expression"""
68+
if not isinstance(value, str):
69+
value = str(value)
70+
6771
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
6872
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
6973
return value
7074

7175
@field_validator("displayed_name")
7276
def displayed_name_validate_regular_expression(cls, value):
7377
"""Validates the regular expression"""
78+
if not isinstance(value, str):
79+
value = str(value)
80+
7481
if not re.match(r"^[0-9a-zA-Z\s_-]+$", value):
7582
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s_-]+$/")
7683
return value
7784

7885
@field_validator("name")
7986
def name_validate_regular_expression(cls, value):
8087
"""Validates the regular expression"""
88+
if not isinstance(value, str):
89+
value = str(value)
90+
8191
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
8292
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
8393
return value
8494

8595
@field_validator("url")
8696
def url_validate_regular_expression(cls, value):
8797
"""Validates the regular expression"""
98+
if not isinstance(value, str):
99+
value = str(value)
100+
88101
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
89102
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
90103
return value
91104

92105
model_config = ConfigDict(
93-
populate_by_name=True,
106+
validate_by_name=True,
107+
validate_by_alias=True,
94108
validate_assignment=True,
95109
protected_namespaces=(),
96110
)
@@ -101,8 +115,7 @@ def to_str(self) -> str:
101115

102116
def to_json(self) -> str:
103117
"""Returns the JSON representation of the model using alias"""
104-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
105-
return json.dumps(self.to_dict())
118+
return json.dumps(to_jsonable_python(self.to_dict()))
106119

107120
@classmethod
108121
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/error_message_response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, StrictStr
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Self
2324

2425

@@ -32,7 +33,8 @@ class ErrorMessageResponse(BaseModel):
3233
__properties: ClassVar[List[str]] = ["error", "message"]
3334

3435
model_config = ConfigDict(
35-
populate_by_name=True,
36+
validate_by_name=True,
37+
validate_by_alias=True,
3638
validate_assignment=True,
3739
protected_namespaces=(),
3840
)
@@ -43,8 +45,7 @@ def to_str(self) -> str:
4345

4446
def to_json(self) -> str:
4547
"""Returns the JSON representation of the model using alias"""
46-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
47-
return json.dumps(self.to_dict())
48+
return json.dumps(to_jsonable_python(self.to_dict()))
4849

4950
@classmethod
5051
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/get_chat_model_response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, StrictStr
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Self
2324

2425
from stackit.modelserving.models.chat_model_details import ChatModelDetails
@@ -34,7 +35,8 @@ class GetChatModelResponse(BaseModel):
3435
__properties: ClassVar[List[str]] = ["message", "model"]
3536

3637
model_config = ConfigDict(
37-
populate_by_name=True,
38+
validate_by_name=True,
39+
validate_by_alias=True,
3840
validate_assignment=True,
3941
protected_namespaces=(),
4042
)
@@ -45,8 +47,7 @@ def to_str(self) -> str:
4547

4648
def to_json(self) -> str:
4749
"""Returns the JSON representation of the model using alias"""
48-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49-
return json.dumps(self.to_dict())
50+
return json.dumps(to_jsonable_python(self.to_dict()))
5051

5152
@classmethod
5253
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/get_embeddings_model_resp.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, StrictStr
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Self
2324

2425
from stackit.modelserving.models.embedding_model_details import EmbeddingModelDetails
@@ -34,7 +35,8 @@ class GetEmbeddingsModelResp(BaseModel):
3435
__properties: ClassVar[List[str]] = ["message", "model"]
3536

3637
model_config = ConfigDict(
37-
populate_by_name=True,
38+
validate_by_name=True,
39+
validate_by_alias=True,
3840
validate_assignment=True,
3941
protected_namespaces=(),
4042
)
@@ -45,8 +47,7 @@ def to_str(self) -> str:
4547

4648
def to_json(self) -> str:
4749
"""Returns the JSON representation of the model using alias"""
48-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49-
return json.dumps(self.to_dict())
50+
return json.dumps(to_jsonable_python(self.to_dict()))
5051

5152
@classmethod
5253
def from_json(cls, json_str: str) -> Optional[Self]:

services/modelserving/src/stackit/modelserving/models/get_token_response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any, ClassVar, Dict, List, Optional, Set
2020

2121
from pydantic import BaseModel, ConfigDict, StrictStr
22+
from pydantic_core import to_jsonable_python
2223
from typing_extensions import Self
2324

2425
from stackit.modelserving.models.token import Token
@@ -34,7 +35,8 @@ class GetTokenResponse(BaseModel):
3435
__properties: ClassVar[List[str]] = ["message", "token"]
3536

3637
model_config = ConfigDict(
37-
populate_by_name=True,
38+
validate_by_name=True,
39+
validate_by_alias=True,
3840
validate_assignment=True,
3941
protected_namespaces=(),
4042
)
@@ -45,8 +47,7 @@ def to_str(self) -> str:
4547

4648
def to_json(self) -> str:
4749
"""Returns the JSON representation of the model using alias"""
48-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49-
return json.dumps(self.to_dict())
50+
return json.dumps(to_jsonable_python(self.to_dict()))
5051

5152
@classmethod
5253
def from_json(cls, json_str: str) -> Optional[Self]:

0 commit comments

Comments
 (0)