diff --git a/services/modelserving/oas_commit b/services/modelserving/oas_commit new file mode 100644 index 000000000..e3713dde3 --- /dev/null +++ b/services/modelserving/oas_commit @@ -0,0 +1 @@ +0e64886dd0847341800d7191ed193b75413be998 diff --git a/services/modelserving/src/stackit/modelserving/api/default_api.py b/services/modelserving/src/stackit/modelserving/api/default_api.py index a40d5c659..c0b4a9e41 100644 --- a/services/modelserving/src/stackit/modelserving/api/default_api.py +++ b/services/modelserving/src/stackit/modelserving/api/default_api.py @@ -13,6 +13,7 @@ """ # noqa: E501 from typing import Any, Dict, List, Optional, Tuple, Union +from uuid import UUID from pydantic import Field, StrictFloat, StrictInt, StrictStr, validate_call from stackit.core.configuration import Configuration @@ -52,7 +53,7 @@ def __init__(self, configuration: Configuration = None) -> None: def create_token( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], + project_id: Annotated[UUID, Field(description="portal project id")], create_token_payload: Optional[CreateTokenPayload] = None, _request_timeout: Union[ None, @@ -71,7 +72,7 @@ def create_token( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param create_token_payload: :type create_token_payload: CreateTokenPayload :param _request_timeout: timeout setting for this request. If one @@ -124,7 +125,7 @@ def create_token( def create_token_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], + project_id: Annotated[UUID, Field(description="portal project id")], create_token_payload: Optional[CreateTokenPayload] = None, _request_timeout: Union[ None, @@ -143,7 +144,7 @@ def create_token_with_http_info( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param create_token_payload: :type create_token_payload: CreateTokenPayload :param _request_timeout: timeout setting for this request. If one @@ -196,7 +197,7 @@ def create_token_with_http_info( def create_token_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], + project_id: Annotated[UUID, Field(description="portal project id")], create_token_payload: Optional[CreateTokenPayload] = None, _request_timeout: Union[ None, @@ -215,7 +216,7 @@ def create_token_without_preload_content( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param create_token_payload: :type create_token_payload: CreateTokenPayload :param _request_timeout: timeout setting for this request. If one @@ -328,8 +329,8 @@ def _create_token_serialize( def delete_token( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -347,9 +348,9 @@ def delete_token( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -400,8 +401,8 @@ def delete_token( def delete_token_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -419,9 +420,9 @@ def delete_token_with_http_info( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -472,8 +473,8 @@ def delete_token_with_http_info( def delete_token_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -491,9 +492,9 @@ def delete_token_without_preload_content( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -596,7 +597,7 @@ def _delete_token_serialize( def get_chat_model( self, region_id: Annotated[StrictStr, Field(description="region name")], - model_id: Annotated[StrictStr, Field(description="model id")], + model_id: Annotated[UUID, Field(description="model id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -614,7 +615,7 @@ def get_chat_model( :param region_id: region name (required) :type region_id: str :param model_id: model id (required) - :type model_id: str + :type model_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -663,7 +664,7 @@ def get_chat_model( def get_chat_model_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - model_id: Annotated[StrictStr, Field(description="model id")], + model_id: Annotated[UUID, Field(description="model id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -681,7 +682,7 @@ def get_chat_model_with_http_info( :param region_id: region name (required) :type region_id: str :param model_id: model id (required) - :type model_id: str + :type model_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -730,7 +731,7 @@ def get_chat_model_with_http_info( def get_chat_model_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - model_id: Annotated[StrictStr, Field(description="model id")], + model_id: Annotated[UUID, Field(description="model id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -748,7 +749,7 @@ def get_chat_model_without_preload_content( :param region_id: region name (required) :type region_id: str :param model_id: model id (required) - :type model_id: str + :type model_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -846,7 +847,7 @@ def _get_chat_model_serialize( def get_embedding_model( self, region_id: Annotated[StrictStr, Field(description="region name")], - model_id: Annotated[StrictStr, Field(description="model id")], + model_id: Annotated[UUID, Field(description="model id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -864,7 +865,7 @@ def get_embedding_model( :param region_id: region name (required) :type region_id: str :param model_id: model id (required) - :type model_id: str + :type model_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -913,7 +914,7 @@ def get_embedding_model( def get_embedding_model_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - model_id: Annotated[StrictStr, Field(description="model id")], + model_id: Annotated[UUID, Field(description="model id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -931,7 +932,7 @@ def get_embedding_model_with_http_info( :param region_id: region name (required) :type region_id: str :param model_id: model id (required) - :type model_id: str + :type model_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -980,7 +981,7 @@ def get_embedding_model_with_http_info( def get_embedding_model_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - model_id: Annotated[StrictStr, Field(description="model id")], + model_id: Annotated[UUID, Field(description="model id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -998,7 +999,7 @@ def get_embedding_model_without_preload_content( :param region_id: region name (required) :type region_id: str :param model_id: model id (required) - :type model_id: str + :type model_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1096,8 +1097,8 @@ def _get_embedding_model_serialize( def get_token( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -1115,9 +1116,9 @@ def get_token( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1168,8 +1169,8 @@ def get_token( def get_token_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -1187,9 +1188,9 @@ def get_token_with_http_info( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1240,8 +1241,8 @@ def get_token_with_http_info( def get_token_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -1259,9 +1260,9 @@ def get_token_without_preload_content( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1599,7 +1600,7 @@ def _list_models_serialize( def list_tokens( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], + project_id: Annotated[UUID, Field(description="portal project id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -1617,7 +1618,7 @@ def list_tokens( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1666,7 +1667,7 @@ def list_tokens( def list_tokens_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], + project_id: Annotated[UUID, Field(description="portal project id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -1684,7 +1685,7 @@ def list_tokens_with_http_info( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1733,7 +1734,7 @@ def list_tokens_with_http_info( def list_tokens_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], + project_id: Annotated[UUID, Field(description="portal project id")], _request_timeout: Union[ None, Annotated[StrictFloat, Field(gt=0)], @@ -1751,7 +1752,7 @@ def list_tokens_without_preload_content( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of @@ -1849,8 +1850,8 @@ def _list_tokens_serialize( def partial_update_token( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], partial_update_token_payload: Optional[PartialUpdateTokenPayload] = None, _request_timeout: Union[ None, @@ -1869,9 +1870,9 @@ def partial_update_token( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param partial_update_token_payload: :type partial_update_token_payload: PartialUpdateTokenPayload :param _request_timeout: timeout setting for this request. If one @@ -1925,8 +1926,8 @@ def partial_update_token( def partial_update_token_with_http_info( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], partial_update_token_payload: Optional[PartialUpdateTokenPayload] = None, _request_timeout: Union[ None, @@ -1945,9 +1946,9 @@ def partial_update_token_with_http_info( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param partial_update_token_payload: :type partial_update_token_payload: PartialUpdateTokenPayload :param _request_timeout: timeout setting for this request. If one @@ -2001,8 +2002,8 @@ def partial_update_token_with_http_info( def partial_update_token_without_preload_content( self, region_id: Annotated[StrictStr, Field(description="region name")], - project_id: Annotated[StrictStr, Field(description="portal project id")], - t_id: Annotated[StrictStr, Field(description="token id")], + project_id: Annotated[UUID, Field(description="portal project id")], + t_id: Annotated[UUID, Field(description="token id")], partial_update_token_payload: Optional[PartialUpdateTokenPayload] = None, _request_timeout: Union[ None, @@ -2021,9 +2022,9 @@ def partial_update_token_without_preload_content( :param region_id: region name (required) :type region_id: str :param project_id: portal project id (required) - :type project_id: str + :type project_id: UUID :param t_id: token id (required) - :type t_id: str + :type t_id: UUID :param partial_update_token_payload: :type partial_update_token_payload: PartialUpdateTokenPayload :param _request_timeout: timeout setting for this request. If one diff --git a/services/modelserving/src/stackit/modelserving/api_client.py b/services/modelserving/src/stackit/modelserving/api_client.py index cfc3ad66f..b0dfa8cfe 100644 --- a/services/modelserving/src/stackit/modelserving/api_client.py +++ b/services/modelserving/src/stackit/modelserving/api_client.py @@ -13,11 +13,13 @@ """ # noqa: E501 import datetime +import decimal import json import mimetypes import os import re import tempfile +import uuid from enum import Enum from typing import Dict, List, Optional, Tuple, Union from urllib.parse import quote @@ -64,8 +66,10 @@ class ApiClient: "bool": bool, "date": datetime.date, "datetime": datetime.datetime, + "decimal": decimal.Decimal, "object": object, } + _pool = None def __init__(self, configuration, header_name=None, header_value=None, cookie=None) -> None: self.config: Configuration = configuration @@ -268,7 +272,7 @@ def response_deserialize( return_data = self.__deserialize_file(response_data) elif response_type is not None: match = None - content_type = response_data.getheader("content-type") + content_type = response_data.headers.get("content-type") if content_type is not None: match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type) encoding = match.group(1) if match else "utf-8" @@ -285,7 +289,7 @@ def response_deserialize( return ApiResponse( status_code=response_data.status, data=return_data, - headers=response_data.getheaders(), + headers=response_data.headers, raw_data=response_data.data, ) @@ -297,6 +301,7 @@ def sanitize_for_serialization(self, obj): If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. + If obj is decimal.Decimal return string representation. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is OpenAPI model, return the properties dict. @@ -312,12 +317,16 @@ def sanitize_for_serialization(self, obj): return obj.get_secret_value() elif isinstance(obj, self.PRIMITIVE_TYPES): return obj + elif isinstance(obj, uuid.UUID): + return str(obj) elif isinstance(obj, list): return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj] elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) elif isinstance(obj, (datetime.datetime, datetime.date)): return obj.isoformat() + elif isinstance(obj, decimal.Decimal): + return str(obj) elif isinstance(obj, dict): obj_dict = obj @@ -327,7 +336,7 @@ def sanitize_for_serialization(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - if hasattr(obj, "to_dict") and callable(obj.to_dict): + if hasattr(obj, "to_dict") and callable(getattr(obj, "to_dict")): # noqa: B009 obj_dict = obj.to_dict() else: obj_dict = obj.__dict__ @@ -355,7 +364,7 @@ def deserialize(self, response_text: str, response_type: str, content_type: Opti data = json.loads(response_text) except ValueError: data = response_text - elif re.match(r"^application/(json|[\w!#$&.+-^_]+\+json)\s*(;|$)", content_type, re.IGNORECASE): + elif re.match(r"^application/(json|[\w!#$&.+\-^_]+\+json)\s*(;|$)", content_type, re.IGNORECASE): if response_text == "": data = "" else: @@ -401,12 +410,14 @@ def __deserialize(self, data, klass): if klass in self.PRIMITIVE_TYPES: return self.__deserialize_primitive(data, klass) - elif klass == object: + elif klass is object: return self.__deserialize_object(data) - elif klass == datetime.date: + elif klass is datetime.date: return self.__deserialize_date(data) - elif klass == datetime.datetime: + elif klass is datetime.datetime: return self.__deserialize_datetime(data) + elif klass is decimal.Decimal: + return decimal.Decimal(data) elif issubclass(klass, Enum): return self.__deserialize_enum(data, klass) else: @@ -554,12 +565,14 @@ def __deserialize_file(self, response): os.close(fd) os.remove(path) - content_disposition = response.getheader("Content-Disposition") + content_disposition = response.headers.get("Content-Disposition") if content_disposition: m = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition) if m is None: raise ValueError("Unexpected 'content-disposition' header value") - filename = m.group(1) + filename = os.path.basename(m.group(1)) # Strip any directory traversal + if filename in ("", ".", ".."): # fall back to tmp filename + filename = os.path.basename(path) path = os.path.join(os.path.dirname(path), filename) with open(path, "wb") as f: diff --git a/services/modelserving/src/stackit/modelserving/exceptions.py b/services/modelserving/src/stackit/modelserving/exceptions.py index f11ebd259..6787e5981 100644 --- a/services/modelserving/src/stackit/modelserving/exceptions.py +++ b/services/modelserving/src/stackit/modelserving/exceptions.py @@ -130,7 +130,7 @@ def __init__( self.body = http_resp.data.decode("utf-8") except Exception: # noqa: S110 pass - self.headers = http_resp.getheaders() + self.headers = http_resp.headers @classmethod def from_response( diff --git a/services/modelserving/src/stackit/modelserving/models/__init__.py b/services/modelserving/src/stackit/modelserving/models/__init__.py index 16af77f25..180e0962a 100644 --- a/services/modelserving/src/stackit/modelserving/models/__init__.py +++ b/services/modelserving/src/stackit/modelserving/models/__init__.py @@ -13,7 +13,6 @@ Do not edit the class manually. """ # noqa: E501 - # import models into model package from stackit.modelserving.models.chat_model_details import ChatModelDetails from stackit.modelserving.models.create_token_payload import CreateTokenPayload diff --git a/services/modelserving/src/stackit/modelserving/models/chat_model_details.py b/services/modelserving/src/stackit/modelserving/models/chat_model_details.py index f61c56c9e..06cba434c 100644 --- a/services/modelserving/src/stackit/modelserving/models/chat_model_details.py +++ b/services/modelserving/src/stackit/modelserving/models/chat_model_details.py @@ -18,6 +18,7 @@ import pprint import re # noqa: F401 from typing import Any, ClassVar, Dict, List, Optional, Set +from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing_extensions import Annotated, Self @@ -35,7 +36,7 @@ class ChatModelDetails(BaseModel): context_length: StrictInt = Field(alias="contextLength") description: Annotated[str, Field(strict=True, max_length=2000)] displayed_name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(alias="displayedName") - id: StrictStr = Field(description="generated uuid to identify a model") + id: UUID = Field(description="generated uuid to identify a model") name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(description="huggingface name") quantization_method: Optional[StrictStr] = Field(default=None, alias="quantizationMethod") region: StrictStr @@ -154,9 +155,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in skus (list) _items = [] if self.skus: - for _item in self.skus: - if _item: - _items.append(_item.to_dict()) + for _item_skus in self.skus: + if _item_skus: + _items.append(_item_skus.to_dict()) _dict["skus"] = _items return _dict diff --git a/services/modelserving/src/stackit/modelserving/models/embedding_model_details.py b/services/modelserving/src/stackit/modelserving/models/embedding_model_details.py index 5a83919e9..e83acd824 100644 --- a/services/modelserving/src/stackit/modelserving/models/embedding_model_details.py +++ b/services/modelserving/src/stackit/modelserving/models/embedding_model_details.py @@ -18,6 +18,7 @@ import pprint import re # noqa: F401 from typing import Any, ClassVar, Dict, List, Optional, Set +from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator from typing_extensions import Annotated, Self @@ -33,7 +34,7 @@ class EmbeddingModelDetails(BaseModel): category: StrictStr description: Annotated[str, Field(strict=True, max_length=2000)] displayed_name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(alias="displayedName") - id: StrictStr = Field(description="generated uuid to identify a model") + id: UUID = Field(description="generated uuid to identify a model") name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(description="huggingface name") output_dimension: StrictInt = Field(alias="outputDimension") region: StrictStr @@ -128,9 +129,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in skus (list) _items = [] if self.skus: - for _item in self.skus: - if _item: - _items.append(_item.to_dict()) + for _item_skus in self.skus: + if _item_skus: + _items.append(_item_skus.to_dict()) _dict["skus"] = _items return _dict diff --git a/services/modelserving/src/stackit/modelserving/models/list_models_response.py b/services/modelserving/src/stackit/modelserving/models/list_models_response.py index 644526c48..7a9c5e880 100644 --- a/services/modelserving/src/stackit/modelserving/models/list_models_response.py +++ b/services/modelserving/src/stackit/modelserving/models/list_models_response.py @@ -73,9 +73,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in models (list) _items = [] if self.models: - for _item in self.models: - if _item: - _items.append(_item.to_dict()) + for _item_models in self.models: + if _item_models: + _items.append(_item_models.to_dict()) _dict["models"] = _items return _dict diff --git a/services/modelserving/src/stackit/modelserving/models/list_token_resp.py b/services/modelserving/src/stackit/modelserving/models/list_token_resp.py index e427807a5..678c57d68 100644 --- a/services/modelserving/src/stackit/modelserving/models/list_token_resp.py +++ b/services/modelserving/src/stackit/modelserving/models/list_token_resp.py @@ -73,9 +73,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in tokens (list) _items = [] if self.tokens: - for _item in self.tokens: - if _item: - _items.append(_item.to_dict()) + for _item_tokens in self.tokens: + if _item_tokens: + _items.append(_item_tokens.to_dict()) _dict["tokens"] = _items return _dict diff --git a/services/modelserving/src/stackit/modelserving/models/model.py b/services/modelserving/src/stackit/modelserving/models/model.py index e72a91f77..8018d86fe 100644 --- a/services/modelserving/src/stackit/modelserving/models/model.py +++ b/services/modelserving/src/stackit/modelserving/models/model.py @@ -18,6 +18,7 @@ import pprint import re # noqa: F401 from typing import Any, ClassVar, Dict, List, Optional, Set +from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator from typing_extensions import Annotated, Self @@ -33,7 +34,7 @@ class Model(BaseModel): category: StrictStr description: Annotated[str, Field(strict=True, max_length=2000)] displayed_name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(alias="displayedName") - id: StrictStr = Field(description="generated uuid to identify a model") + id: UUID = Field(description="generated uuid to identify a model") name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] = Field(description="huggingface name") region: StrictStr skus: List[SKU] @@ -121,9 +122,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in skus (list) _items = [] if self.skus: - for _item in self.skus: - if _item: - _items.append(_item.to_dict()) + for _item_skus in self.skus: + if _item_skus: + _items.append(_item_skus.to_dict()) _dict["skus"] = _items return _dict diff --git a/services/modelserving/src/stackit/modelserving/models/token.py b/services/modelserving/src/stackit/modelserving/models/token.py index af54ee7f5..62b055753 100644 --- a/services/modelserving/src/stackit/modelserving/models/token.py +++ b/services/modelserving/src/stackit/modelserving/models/token.py @@ -19,6 +19,7 @@ import re # noqa: F401 from datetime import datetime from typing import Any, ClassVar, Dict, List, Optional, Set +from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator from typing_extensions import Annotated, Self @@ -30,7 +31,7 @@ class Token(BaseModel): """ # noqa: E501 description: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = None - id: StrictStr + id: UUID name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] region: StrictStr state: StrictStr diff --git a/services/modelserving/src/stackit/modelserving/models/token_created.py b/services/modelserving/src/stackit/modelserving/models/token_created.py index e043eb1fe..3984b297b 100644 --- a/services/modelserving/src/stackit/modelserving/models/token_created.py +++ b/services/modelserving/src/stackit/modelserving/models/token_created.py @@ -19,6 +19,7 @@ import re # noqa: F401 from datetime import datetime from typing import Any, ClassVar, Dict, List, Optional, Set +from uuid import UUID from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator from typing_extensions import Annotated, Self @@ -31,7 +32,7 @@ class TokenCreated(BaseModel): content: Annotated[str, Field(min_length=1, strict=True, max_length=200)] description: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = None - id: StrictStr + id: UUID name: Annotated[str, Field(min_length=1, strict=True, max_length=200)] region: StrictStr state: StrictStr diff --git a/services/modelserving/src/stackit/modelserving/rest.py b/services/modelserving/src/stackit/modelserving/rest.py index 2acbb8ff6..26acf8374 100644 --- a/services/modelserving/src/stackit/modelserving/rest.py +++ b/services/modelserving/src/stackit/modelserving/rest.py @@ -39,12 +39,17 @@ def read(self): self.data = self.response.content return self.data + @property + def headers(self): + """Returns a dictionary of response headers.""" + return self.response.headers + def getheaders(self): - """Returns a dictionary of the response headers.""" + """Returns a dictionary of the response headers; use ``headers`` instead.""" return self.response.headers def getheader(self, name, default=None): - """Returns a given response header.""" + """Returns a given response header; use ``headers.get()`` instead.""" return self.response.headers.get(name, default) @@ -94,6 +99,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, data=request_body, headers=headers, + timeout=_request_timeout, ) elif content_type == "application/x-www-form-urlencoded": r = self.session.request( @@ -101,6 +107,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, params=post_params, headers=headers, + timeout=_request_timeout, ) elif content_type == "multipart/form-data": # must del headers['Content-Type'], or the correct @@ -114,6 +121,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, files=post_params, headers=headers, + timeout=_request_timeout, ) # Pass a `string` parameter directly in the body to support # other content types than JSON when `body` argument is @@ -124,10 +132,17 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, data=body, headers=headers, + timeout=_request_timeout, ) elif headers["Content-Type"].startswith("text/") and isinstance(body, bool): request_body = "true" if body else "false" - r = self.session.request(method, url, data=request_body, headers=headers) + r = self.session.request( + method, + url, + data=request_body, + headers=headers, + timeout=_request_timeout, + ) else: # Cannot generate the request from given parameters msg = """Cannot prepare a request message for provided @@ -141,6 +156,7 @@ def request(self, method, url, headers=None, body=None, post_params=None, _reque url, params={}, headers=headers, + timeout=_request_timeout, ) except requests.exceptions.SSLError as e: msg = "\n".join([type(e).__name__, str(e)])