stackit-modelserving 0.0.1a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- stackit/modelserving/__init__.py +55 -0
- stackit/modelserving/api/__init__.py +4 -0
- stackit/modelserving/api/default_api.py +2137 -0
- stackit/modelserving/api_client.py +627 -0
- stackit/modelserving/api_response.py +23 -0
- stackit/modelserving/configuration.py +138 -0
- stackit/modelserving/exceptions.py +199 -0
- stackit/modelserving/models/__init__.py +36 -0
- stackit/modelserving/models/chat_model_details.py +189 -0
- stackit/modelserving/models/create_token_payload.py +108 -0
- stackit/modelserving/models/create_token_response.py +93 -0
- stackit/modelserving/models/embedding_model_details.py +160 -0
- stackit/modelserving/models/error_message_response.py +83 -0
- stackit/modelserving/models/get_chat_model_response.py +93 -0
- stackit/modelserving/models/get_embeddings_model_resp.py +93 -0
- stackit/modelserving/models/get_token_response.py +93 -0
- stackit/modelserving/models/list_models_response.py +99 -0
- stackit/modelserving/models/list_token_resp.py +99 -0
- stackit/modelserving/models/message_response.py +82 -0
- stackit/modelserving/models/model.py +153 -0
- stackit/modelserving/models/partial_update_token_payload.py +104 -0
- stackit/modelserving/models/sku.py +84 -0
- stackit/modelserving/models/token.py +122 -0
- stackit/modelserving/models/token_created.py +131 -0
- stackit/modelserving/models/update_token_response.py +93 -0
- stackit/modelserving/py.typed +0 -0
- stackit/modelserving/rest.py +149 -0
- stackit_modelserving-0.0.1a0.dist-info/METADATA +45 -0
- stackit_modelserving-0.0.1a0.dist-info/RECORD +30 -0
- stackit_modelserving-0.0.1a0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Model Serving API
|
|
5
|
+
|
|
6
|
+
This API provides endpoints for the model serving api
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
|
9
|
+
Contact: model-serving@mail.schwarz
|
|
10
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
11
|
+
|
|
12
|
+
Do not edit the class manually.
|
|
13
|
+
""" # noqa: E501 docstring might be too long
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class HostConfiguration:
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
region=None,
|
|
22
|
+
server_index=None,
|
|
23
|
+
server_variables=None,
|
|
24
|
+
server_operation_index=None,
|
|
25
|
+
server_operation_variables=None,
|
|
26
|
+
ignore_operation_servers=False,
|
|
27
|
+
) -> None:
|
|
28
|
+
print(
|
|
29
|
+
"WARNING: STACKIT will move to a new way of specifying regions, where the region is provided\n",
|
|
30
|
+
"as a function argument instead of being set in the client configuration.\n"
|
|
31
|
+
"Once all services have migrated, the methods to specify the region in the client configuration "
|
|
32
|
+
"will be removed.",
|
|
33
|
+
)
|
|
34
|
+
"""Constructor
|
|
35
|
+
"""
|
|
36
|
+
self._base_path = "https://model-serving.api.stackit.cloud"
|
|
37
|
+
"""Default Base url
|
|
38
|
+
"""
|
|
39
|
+
self.server_index = 0 if server_index is None else server_index
|
|
40
|
+
self.server_operation_index = server_operation_index or {}
|
|
41
|
+
"""Default server index
|
|
42
|
+
"""
|
|
43
|
+
self.server_variables = server_variables or {}
|
|
44
|
+
if region:
|
|
45
|
+
self.server_variables["region"] = "{}.".format(region)
|
|
46
|
+
self.server_operation_variables = server_operation_variables or {}
|
|
47
|
+
"""Default server variables
|
|
48
|
+
"""
|
|
49
|
+
self.ignore_operation_servers = ignore_operation_servers
|
|
50
|
+
"""Ignore operation servers
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def get_host_settings(self):
|
|
54
|
+
"""Gets an array of host settings
|
|
55
|
+
|
|
56
|
+
:return: An array of host settings
|
|
57
|
+
"""
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
"url": "https://model-serving.api.stackit.cloud",
|
|
61
|
+
"description": "No description provided",
|
|
62
|
+
"variables": {
|
|
63
|
+
"region": {
|
|
64
|
+
"description": "No description provided",
|
|
65
|
+
"default_value": "global",
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
def get_host_from_settings(self, index, variables=None, servers=None):
|
|
72
|
+
"""Gets host URL based on the index and variables
|
|
73
|
+
:param index: array index of the host settings
|
|
74
|
+
:param variables: hash of variable and the corresponding value
|
|
75
|
+
:param servers: an array of host settings or None
|
|
76
|
+
:error: if a region is given for a global url
|
|
77
|
+
:return: URL based on host settings
|
|
78
|
+
"""
|
|
79
|
+
if index is None:
|
|
80
|
+
return self._base_path
|
|
81
|
+
|
|
82
|
+
variables = {} if variables is None else variables
|
|
83
|
+
servers = self.get_host_settings() if servers is None else servers
|
|
84
|
+
|
|
85
|
+
try:
|
|
86
|
+
server = servers[index]
|
|
87
|
+
except IndexError:
|
|
88
|
+
raise ValueError(
|
|
89
|
+
"Invalid index {0} when selecting the host settings. "
|
|
90
|
+
"Must be less than {1}".format(index, len(servers))
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
url = server["url"]
|
|
94
|
+
|
|
95
|
+
# check if environment variable was provided for region
|
|
96
|
+
# if nothing was set this is None
|
|
97
|
+
region_env = os.environ.get("STACKIT_REGION")
|
|
98
|
+
|
|
99
|
+
# go through variables and replace placeholders
|
|
100
|
+
for variable_name, variable in server.get("variables", {}).items():
|
|
101
|
+
# If a region is provided by the user for a global url
|
|
102
|
+
# return an error (except for providing via environment variable).
|
|
103
|
+
# The region is provided as a function argument instead of being set in the client configuration.
|
|
104
|
+
if (
|
|
105
|
+
variable_name == "region"
|
|
106
|
+
and (variable["default_value"] == "global" or variable["default_value"] == "")
|
|
107
|
+
and region_env is None
|
|
108
|
+
and variables.get(variable_name) is not None
|
|
109
|
+
):
|
|
110
|
+
raise ValueError(
|
|
111
|
+
"this API does not support setting a region in the the client configuration, "
|
|
112
|
+
"please check if the region can be specified as a function parameter"
|
|
113
|
+
)
|
|
114
|
+
used_value = variables.get(variable_name, variable["default_value"])
|
|
115
|
+
|
|
116
|
+
if "enum_values" in variable and used_value not in variable["enum_values"]:
|
|
117
|
+
given_value = variables[variable_name].replace(".", "")
|
|
118
|
+
valid_values = [v.replace(".", "") for v in variable["enum_values"]]
|
|
119
|
+
raise ValueError(
|
|
120
|
+
"The variable `{0}` in the host URL has invalid value '{1}'. Must be '{2}'.".format(
|
|
121
|
+
variable_name, given_value, valid_values
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
url = url.replace("{" + variable_name + "}", used_value)
|
|
126
|
+
|
|
127
|
+
return url
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def host(self):
|
|
131
|
+
"""Return generated host."""
|
|
132
|
+
return self.get_host_from_settings(self.server_index, variables=self.server_variables)
|
|
133
|
+
|
|
134
|
+
@host.setter
|
|
135
|
+
def host(self, value):
|
|
136
|
+
"""Fix base path."""
|
|
137
|
+
self._base_path = value
|
|
138
|
+
self.server_index = None
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Model Serving API
|
|
5
|
+
|
|
6
|
+
This API provides endpoints for the model serving api
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
|
9
|
+
Contact: model-serving@mail.schwarz
|
|
10
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
11
|
+
|
|
12
|
+
Do not edit the class manually.
|
|
13
|
+
""" # noqa: E501 docstring might be too long
|
|
14
|
+
|
|
15
|
+
from typing import Any, Optional
|
|
16
|
+
|
|
17
|
+
from typing_extensions import Self
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OpenApiException(Exception):
|
|
21
|
+
"""The base exception class for all OpenAPIExceptions"""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ApiTypeError(OpenApiException, TypeError):
|
|
25
|
+
def __init__(self, msg, path_to_item=None, valid_classes=None, key_type=None) -> None:
|
|
26
|
+
"""Raises an exception for TypeErrors
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
msg (str): the exception message
|
|
30
|
+
|
|
31
|
+
Keyword Args:
|
|
32
|
+
path_to_item (list): a list of keys an indices to get to the
|
|
33
|
+
current_item
|
|
34
|
+
None if unset
|
|
35
|
+
valid_classes (tuple): the primitive classes that current item
|
|
36
|
+
should be an instance of
|
|
37
|
+
None if unset
|
|
38
|
+
key_type (bool): False if our value is a value in a dict
|
|
39
|
+
True if it is a key in a dict
|
|
40
|
+
False if our item is an item in a list
|
|
41
|
+
None if unset
|
|
42
|
+
"""
|
|
43
|
+
self.path_to_item = path_to_item
|
|
44
|
+
self.valid_classes = valid_classes
|
|
45
|
+
self.key_type = key_type
|
|
46
|
+
full_msg = msg
|
|
47
|
+
if path_to_item:
|
|
48
|
+
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
49
|
+
super(ApiTypeError, self).__init__(full_msg)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ApiValueError(OpenApiException, ValueError):
|
|
53
|
+
def __init__(self, msg, path_to_item=None) -> None:
|
|
54
|
+
"""
|
|
55
|
+
Args:
|
|
56
|
+
msg (str): the exception message
|
|
57
|
+
|
|
58
|
+
Keyword Args:
|
|
59
|
+
path_to_item (list) the path to the exception in the
|
|
60
|
+
received_data dict. None if unset
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
self.path_to_item = path_to_item
|
|
64
|
+
full_msg = msg
|
|
65
|
+
if path_to_item:
|
|
66
|
+
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
67
|
+
super(ApiValueError, self).__init__(full_msg)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class ApiAttributeError(OpenApiException, AttributeError):
|
|
71
|
+
def __init__(self, msg, path_to_item=None) -> None:
|
|
72
|
+
"""
|
|
73
|
+
Raised when an attribute reference or assignment fails.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
msg (str): the exception message
|
|
77
|
+
|
|
78
|
+
Keyword Args:
|
|
79
|
+
path_to_item (None/list) the path to the exception in the
|
|
80
|
+
received_data dict
|
|
81
|
+
"""
|
|
82
|
+
self.path_to_item = path_to_item
|
|
83
|
+
full_msg = msg
|
|
84
|
+
if path_to_item:
|
|
85
|
+
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
86
|
+
super(ApiAttributeError, self).__init__(full_msg)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ApiKeyError(OpenApiException, KeyError):
|
|
90
|
+
def __init__(self, msg, path_to_item=None) -> None:
|
|
91
|
+
"""
|
|
92
|
+
Args:
|
|
93
|
+
msg (str): the exception message
|
|
94
|
+
|
|
95
|
+
Keyword Args:
|
|
96
|
+
path_to_item (None/list) the path to the exception in the
|
|
97
|
+
received_data dict
|
|
98
|
+
"""
|
|
99
|
+
self.path_to_item = path_to_item
|
|
100
|
+
full_msg = msg
|
|
101
|
+
if path_to_item:
|
|
102
|
+
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
|
103
|
+
super(ApiKeyError, self).__init__(full_msg)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class ApiException(OpenApiException):
|
|
107
|
+
|
|
108
|
+
def __init__(
|
|
109
|
+
self,
|
|
110
|
+
status=None,
|
|
111
|
+
reason=None,
|
|
112
|
+
http_resp=None,
|
|
113
|
+
*,
|
|
114
|
+
body: Optional[str] = None,
|
|
115
|
+
data: Optional[Any] = None,
|
|
116
|
+
) -> None:
|
|
117
|
+
self.status = status
|
|
118
|
+
self.reason = reason
|
|
119
|
+
self.body = body
|
|
120
|
+
self.data = data
|
|
121
|
+
self.headers = None
|
|
122
|
+
|
|
123
|
+
if http_resp:
|
|
124
|
+
if self.status is None:
|
|
125
|
+
self.status = http_resp.status
|
|
126
|
+
if self.reason is None:
|
|
127
|
+
self.reason = http_resp.reason
|
|
128
|
+
if self.body is None:
|
|
129
|
+
try:
|
|
130
|
+
self.body = http_resp.data.decode("utf-8")
|
|
131
|
+
except Exception: # noqa: S110
|
|
132
|
+
pass
|
|
133
|
+
self.headers = http_resp.getheaders()
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def from_response(
|
|
137
|
+
cls,
|
|
138
|
+
*,
|
|
139
|
+
http_resp,
|
|
140
|
+
body: Optional[str],
|
|
141
|
+
data: Optional[Any],
|
|
142
|
+
) -> Self:
|
|
143
|
+
if http_resp.status == 400:
|
|
144
|
+
raise BadRequestException(http_resp=http_resp, body=body, data=data)
|
|
145
|
+
|
|
146
|
+
if http_resp.status == 401:
|
|
147
|
+
raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
|
|
148
|
+
|
|
149
|
+
if http_resp.status == 403:
|
|
150
|
+
raise ForbiddenException(http_resp=http_resp, body=body, data=data)
|
|
151
|
+
|
|
152
|
+
if http_resp.status == 404:
|
|
153
|
+
raise NotFoundException(http_resp=http_resp, body=body, data=data)
|
|
154
|
+
|
|
155
|
+
if 500 <= http_resp.status <= 599:
|
|
156
|
+
raise ServiceException(http_resp=http_resp, body=body, data=data)
|
|
157
|
+
raise ApiException(http_resp=http_resp, body=body, data=data)
|
|
158
|
+
|
|
159
|
+
def __str__(self):
|
|
160
|
+
"""Custom error messages for exception"""
|
|
161
|
+
error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
|
|
162
|
+
if self.headers:
|
|
163
|
+
error_message += "HTTP response headers: {0}\n".format(self.headers)
|
|
164
|
+
|
|
165
|
+
if self.data or self.body:
|
|
166
|
+
error_message += "HTTP response body: {0}\n".format(self.data or self.body)
|
|
167
|
+
|
|
168
|
+
return error_message
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class BadRequestException(ApiException):
|
|
172
|
+
pass
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class NotFoundException(ApiException):
|
|
176
|
+
pass
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
class UnauthorizedException(ApiException):
|
|
180
|
+
pass
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class ForbiddenException(ApiException):
|
|
184
|
+
pass
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class ServiceException(ApiException):
|
|
188
|
+
pass
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def render_path(path_to_item):
|
|
192
|
+
"""Returns a string representation of a path"""
|
|
193
|
+
result = ""
|
|
194
|
+
for pth in path_to_item:
|
|
195
|
+
if isinstance(pth, int):
|
|
196
|
+
result += "[{0}]".format(pth)
|
|
197
|
+
else:
|
|
198
|
+
result += "['{0}']".format(pth)
|
|
199
|
+
return result
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# flake8: noqa
|
|
4
|
+
"""
|
|
5
|
+
STACKIT Model Serving API
|
|
6
|
+
|
|
7
|
+
This API provides endpoints for the model serving api
|
|
8
|
+
|
|
9
|
+
The version of the OpenAPI document: 1.0.0
|
|
10
|
+
Contact: model-serving@mail.schwarz
|
|
11
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
12
|
+
|
|
13
|
+
Do not edit the class manually.
|
|
14
|
+
""" # noqa: E501 docstring might be too long
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# import models into model package
|
|
18
|
+
from stackit.modelserving.models.chat_model_details import ChatModelDetails
|
|
19
|
+
from stackit.modelserving.models.create_token_payload import CreateTokenPayload
|
|
20
|
+
from stackit.modelserving.models.create_token_response import CreateTokenResponse
|
|
21
|
+
from stackit.modelserving.models.embedding_model_details import EmbeddingModelDetails
|
|
22
|
+
from stackit.modelserving.models.error_message_response import ErrorMessageResponse
|
|
23
|
+
from stackit.modelserving.models.get_chat_model_response import GetChatModelResponse
|
|
24
|
+
from stackit.modelserving.models.get_embeddings_model_resp import GetEmbeddingsModelResp
|
|
25
|
+
from stackit.modelserving.models.get_token_response import GetTokenResponse
|
|
26
|
+
from stackit.modelserving.models.list_models_response import ListModelsResponse
|
|
27
|
+
from stackit.modelserving.models.list_token_resp import ListTokenResp
|
|
28
|
+
from stackit.modelserving.models.message_response import MessageResponse
|
|
29
|
+
from stackit.modelserving.models.model import Model
|
|
30
|
+
from stackit.modelserving.models.partial_update_token_payload import (
|
|
31
|
+
PartialUpdateTokenPayload,
|
|
32
|
+
)
|
|
33
|
+
from stackit.modelserving.models.sku import SKU
|
|
34
|
+
from stackit.modelserving.models.token import Token
|
|
35
|
+
from stackit.modelserving.models.token_created import TokenCreated
|
|
36
|
+
from stackit.modelserving.models.update_token_response import UpdateTokenResponse
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Model Serving API
|
|
5
|
+
|
|
6
|
+
This API provides endpoints for the model serving api
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
|
9
|
+
Contact: model-serving@mail.schwarz
|
|
10
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
11
|
+
|
|
12
|
+
Do not edit the class manually.
|
|
13
|
+
""" # noqa: E501 docstring might be too long
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import pprint
|
|
19
|
+
import re
|
|
20
|
+
from typing import Any, ClassVar, Dict, List, Optional, Set
|
|
21
|
+
|
|
22
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
|
|
23
|
+
from typing_extensions import Annotated, Self
|
|
24
|
+
|
|
25
|
+
from stackit.modelserving.models.sku import SKU
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ChatModelDetails(BaseModel):
|
|
29
|
+
"""
|
|
30
|
+
ChatModelDetails
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
bits: Optional[StrictInt] = None
|
|
34
|
+
category: StrictStr
|
|
35
|
+
context_length: StrictInt = Field(alias="contextLength")
|
|
36
|
+
description: Annotated[str, Field(strict=True, max_length=2000)]
|
|
37
|
+
displayed_name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(alias="displayedName")
|
|
38
|
+
id: StrictStr = Field(description="generated uuid to identify a model")
|
|
39
|
+
name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(description="huggingface name")
|
|
40
|
+
quantization_method: Optional[StrictStr] = Field(default=None, alias="quantizationMethod")
|
|
41
|
+
region: StrictStr
|
|
42
|
+
size: StrictInt = Field(description="model size in bytes")
|
|
43
|
+
skus: List[SKU]
|
|
44
|
+
tags: List[StrictStr]
|
|
45
|
+
url: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(description="url of the model")
|
|
46
|
+
__properties: ClassVar[List[str]] = [
|
|
47
|
+
"bits",
|
|
48
|
+
"category",
|
|
49
|
+
"contextLength",
|
|
50
|
+
"description",
|
|
51
|
+
"displayedName",
|
|
52
|
+
"id",
|
|
53
|
+
"name",
|
|
54
|
+
"quantizationMethod",
|
|
55
|
+
"region",
|
|
56
|
+
"size",
|
|
57
|
+
"skus",
|
|
58
|
+
"tags",
|
|
59
|
+
"url",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
@field_validator("bits")
|
|
63
|
+
def bits_validate_enum(cls, value):
|
|
64
|
+
"""Validates the enum"""
|
|
65
|
+
if value is None:
|
|
66
|
+
return value
|
|
67
|
+
|
|
68
|
+
if value not in set([1, 2, 4, 8, 16]):
|
|
69
|
+
raise ValueError("must be one of enum values (1, 2, 4, 8, 16)")
|
|
70
|
+
return value
|
|
71
|
+
|
|
72
|
+
@field_validator("category")
|
|
73
|
+
def category_validate_enum(cls, value):
|
|
74
|
+
"""Validates the enum"""
|
|
75
|
+
if value not in set(["standard", "plus", "premium"]):
|
|
76
|
+
raise ValueError("must be one of enum values ('standard', 'plus', 'premium')")
|
|
77
|
+
return value
|
|
78
|
+
|
|
79
|
+
@field_validator("description")
|
|
80
|
+
def description_validate_regular_expression(cls, value):
|
|
81
|
+
"""Validates the regular expression"""
|
|
82
|
+
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
|
|
83
|
+
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
|
|
84
|
+
return value
|
|
85
|
+
|
|
86
|
+
@field_validator("displayed_name")
|
|
87
|
+
def displayed_name_validate_regular_expression(cls, value):
|
|
88
|
+
"""Validates the regular expression"""
|
|
89
|
+
if not re.match(r"^[0-9a-zA-Z\s_-]+$", value):
|
|
90
|
+
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s_-]+$/")
|
|
91
|
+
return value
|
|
92
|
+
|
|
93
|
+
@field_validator("name")
|
|
94
|
+
def name_validate_regular_expression(cls, value):
|
|
95
|
+
"""Validates the regular expression"""
|
|
96
|
+
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
|
|
97
|
+
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
|
|
98
|
+
return value
|
|
99
|
+
|
|
100
|
+
@field_validator("quantization_method")
|
|
101
|
+
def quantization_method_validate_enum(cls, value):
|
|
102
|
+
"""Validates the enum"""
|
|
103
|
+
if value is None:
|
|
104
|
+
return value
|
|
105
|
+
|
|
106
|
+
if value not in set(["PTQ", "QAT"]):
|
|
107
|
+
raise ValueError("must be one of enum values ('PTQ', 'QAT')")
|
|
108
|
+
return value
|
|
109
|
+
|
|
110
|
+
@field_validator("url")
|
|
111
|
+
def url_validate_regular_expression(cls, value):
|
|
112
|
+
"""Validates the regular expression"""
|
|
113
|
+
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
|
|
114
|
+
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
|
|
115
|
+
return value
|
|
116
|
+
|
|
117
|
+
model_config = ConfigDict(
|
|
118
|
+
populate_by_name=True,
|
|
119
|
+
validate_assignment=True,
|
|
120
|
+
protected_namespaces=(),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def to_str(self) -> str:
|
|
124
|
+
"""Returns the string representation of the model using alias"""
|
|
125
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
126
|
+
|
|
127
|
+
def to_json(self) -> str:
|
|
128
|
+
"""Returns the JSON representation of the model using alias"""
|
|
129
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
130
|
+
return json.dumps(self.to_dict())
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
134
|
+
"""Create an instance of ChatModelDetails from a JSON string"""
|
|
135
|
+
return cls.from_dict(json.loads(json_str))
|
|
136
|
+
|
|
137
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
138
|
+
"""Return the dictionary representation of the model using alias.
|
|
139
|
+
|
|
140
|
+
This has the following differences from calling pydantic's
|
|
141
|
+
`self.model_dump(by_alias=True)`:
|
|
142
|
+
|
|
143
|
+
* `None` is only added to the output dict for nullable fields that
|
|
144
|
+
were set at model initialization. Other fields with value `None`
|
|
145
|
+
are ignored.
|
|
146
|
+
"""
|
|
147
|
+
excluded_fields: Set[str] = set([])
|
|
148
|
+
|
|
149
|
+
_dict = self.model_dump(
|
|
150
|
+
by_alias=True,
|
|
151
|
+
exclude=excluded_fields,
|
|
152
|
+
exclude_none=True,
|
|
153
|
+
)
|
|
154
|
+
# override the default output from pydantic by calling `to_dict()` of each item in skus (list)
|
|
155
|
+
_items = []
|
|
156
|
+
if self.skus:
|
|
157
|
+
for _item in self.skus:
|
|
158
|
+
if _item:
|
|
159
|
+
_items.append(_item.to_dict())
|
|
160
|
+
_dict["skus"] = _items
|
|
161
|
+
return _dict
|
|
162
|
+
|
|
163
|
+
@classmethod
|
|
164
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
165
|
+
"""Create an instance of ChatModelDetails from a dict"""
|
|
166
|
+
if obj is None:
|
|
167
|
+
return None
|
|
168
|
+
|
|
169
|
+
if not isinstance(obj, dict):
|
|
170
|
+
return cls.model_validate(obj)
|
|
171
|
+
|
|
172
|
+
_obj = cls.model_validate(
|
|
173
|
+
{
|
|
174
|
+
"bits": obj.get("bits"),
|
|
175
|
+
"category": obj.get("category"),
|
|
176
|
+
"contextLength": obj.get("contextLength"),
|
|
177
|
+
"description": obj.get("description"),
|
|
178
|
+
"displayedName": obj.get("displayedName"),
|
|
179
|
+
"id": obj.get("id"),
|
|
180
|
+
"name": obj.get("name"),
|
|
181
|
+
"quantizationMethod": obj.get("quantizationMethod"),
|
|
182
|
+
"region": obj.get("region"),
|
|
183
|
+
"size": obj.get("size"),
|
|
184
|
+
"skus": [SKU.from_dict(_item) for _item in obj["skus"]] if obj.get("skus") is not None else None,
|
|
185
|
+
"tags": obj.get("tags"),
|
|
186
|
+
"url": obj.get("url"),
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
return _obj
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Model Serving API
|
|
5
|
+
|
|
6
|
+
This API provides endpoints for the model serving api
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
|
9
|
+
Contact: model-serving@mail.schwarz
|
|
10
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
11
|
+
|
|
12
|
+
Do not edit the class manually.
|
|
13
|
+
""" # noqa: E501 docstring might be too long
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import pprint
|
|
19
|
+
import re
|
|
20
|
+
from typing import Any, ClassVar, Dict, List, Optional, Set
|
|
21
|
+
|
|
22
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
|
23
|
+
from typing_extensions import Annotated, Self
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class CreateTokenPayload(BaseModel):
|
|
27
|
+
"""
|
|
28
|
+
CreateTokenPayload
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
description: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = None
|
|
32
|
+
name: Annotated[str, Field(min_length=1, strict=True, max_length=200)]
|
|
33
|
+
ttl_duration: Optional[StrictStr] = Field(
|
|
34
|
+
default=None,
|
|
35
|
+
description="time to live duration. Must be valid duration string. If not set the token will never expire.",
|
|
36
|
+
alias="ttlDuration",
|
|
37
|
+
)
|
|
38
|
+
__properties: ClassVar[List[str]] = ["description", "name", "ttlDuration"]
|
|
39
|
+
|
|
40
|
+
@field_validator("description")
|
|
41
|
+
def description_validate_regular_expression(cls, value):
|
|
42
|
+
"""Validates the regular expression"""
|
|
43
|
+
if value is None:
|
|
44
|
+
return value
|
|
45
|
+
|
|
46
|
+
if not re.match(r"^[0-9a-zA-Z\s.:\/\-]+$", value):
|
|
47
|
+
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s.:\/\-]+$/")
|
|
48
|
+
return value
|
|
49
|
+
|
|
50
|
+
@field_validator("name")
|
|
51
|
+
def name_validate_regular_expression(cls, value):
|
|
52
|
+
"""Validates the regular expression"""
|
|
53
|
+
if not re.match(r"^[0-9a-zA-Z\s_-]+$", value):
|
|
54
|
+
raise ValueError(r"must validate the regular expression /^[0-9a-zA-Z\s_-]+$/")
|
|
55
|
+
return value
|
|
56
|
+
|
|
57
|
+
model_config = ConfigDict(
|
|
58
|
+
populate_by_name=True,
|
|
59
|
+
validate_assignment=True,
|
|
60
|
+
protected_namespaces=(),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def to_str(self) -> str:
|
|
64
|
+
"""Returns the string representation of the model using alias"""
|
|
65
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
66
|
+
|
|
67
|
+
def to_json(self) -> str:
|
|
68
|
+
"""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())
|
|
71
|
+
|
|
72
|
+
@classmethod
|
|
73
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
74
|
+
"""Create an instance of CreateTokenPayload from a JSON string"""
|
|
75
|
+
return cls.from_dict(json.loads(json_str))
|
|
76
|
+
|
|
77
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
78
|
+
"""Return the dictionary representation of the model using alias.
|
|
79
|
+
|
|
80
|
+
This has the following differences from calling pydantic's
|
|
81
|
+
`self.model_dump(by_alias=True)`:
|
|
82
|
+
|
|
83
|
+
* `None` is only added to the output dict for nullable fields that
|
|
84
|
+
were set at model initialization. Other fields with value `None`
|
|
85
|
+
are ignored.
|
|
86
|
+
"""
|
|
87
|
+
excluded_fields: Set[str] = set([])
|
|
88
|
+
|
|
89
|
+
_dict = self.model_dump(
|
|
90
|
+
by_alias=True,
|
|
91
|
+
exclude=excluded_fields,
|
|
92
|
+
exclude_none=True,
|
|
93
|
+
)
|
|
94
|
+
return _dict
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
98
|
+
"""Create an instance of CreateTokenPayload from a dict"""
|
|
99
|
+
if obj is None:
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
if not isinstance(obj, dict):
|
|
103
|
+
return cls.model_validate(obj)
|
|
104
|
+
|
|
105
|
+
_obj = cls.model_validate(
|
|
106
|
+
{"description": obj.get("description"), "name": obj.get("name"), "ttlDuration": obj.get("ttlDuration")}
|
|
107
|
+
)
|
|
108
|
+
return _obj
|