Files
python-sdk/pkg/hanzoai/cloud/models/train_capability.py
T

124 lines
5.3 KiB
Python

# coding: utf-8
"""
Hanzo Cloud API
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
The version of the OpenAPI document: v1
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from hanzoai.cloud.models.train_live import TrainLive
from hanzoai.cloud.models.train_question import TrainQuestion
from hanzoai.cloud.models.train_version import TrainVersion
from typing import Optional, Set
from typing_extensions import Self
class TrainCapability(BaseModel):
"""
TrainCapability
""" # noqa: E501
by: Optional[StrictStr] = None
corrections: Optional[List[StrictStr]] = Field(default=None, description="Corrections are the corrections it is taught from.")
created: Optional[StrictInt] = None
installed: Optional[StrictInt] = Field(default=None, description="Installed is the version in the org's published set, 0 when none.")
live: Optional[TrainLive] = Field(default=None, description="Live is what its installed version did since it went in.")
name: Optional[StrictStr] = Field(default=None, description="Name is its name, one per org; it is the name its versions install under.")
question: Optional[TrainQuestion] = Field(default=None, description="Question is what it answers: the route it is installed behind.")
state: Optional[StrictStr] = Field(default=None, description="State is where it is in its life: draft, trained, evaluated, publishable, installed, active, disabled or needs_validation.")
updated: Optional[StrictInt] = None
version: Optional[StrictInt] = Field(default=None, description="Version is its latest version, 0 in draft.")
versions: Optional[List[TrainVersion]] = Field(default=None, description="Versions are its versions, newest first (one capability read).")
__properties: ClassVar[List[str]] = ["by", "corrections", "created", "installed", "live", "name", "question", "state", "updated", "version", "versions"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of TrainCapability from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of live
if self.live:
_dict['live'] = self.live.to_dict()
# override the default output from pydantic by calling `to_dict()` of question
if self.question:
_dict['question'] = self.question.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in versions (list)
_items = []
if self.versions:
for _item_versions in self.versions:
if _item_versions:
_items.append(_item_versions.to_dict())
_dict['versions'] = _items
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TrainCapability from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"by": obj.get("by"),
"corrections": obj.get("corrections"),
"created": obj.get("created"),
"installed": obj.get("installed"),
"live": TrainLive.from_dict(obj["live"]) if obj.get("live") is not None else None,
"name": obj.get("name"),
"question": TrainQuestion.from_dict(obj["question"]) if obj.get("question") is not None else None,
"state": obj.get("state"),
"updated": obj.get("updated"),
"version": obj.get("version"),
"versions": [TrainVersion.from_dict(_item) for _item in obj["versions"]] if obj.get("versions") is not None else None
})
return _obj