# coding: utf-8
"""
Arize REST API
API specification for the backend data server. The API is hosted globally at https://api.arize.com/v2 or in your own environment.
The version of the OpenAPI document: 2.0.0
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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self
[docs]
class TaskRun(BaseModel):
"""
A task run is an async job that executes the work defined on a task. Runs are created by triggering an existing task (`POST /v2/tasks/{task_id}/trigger`). For `run_experiment` tasks, `experiment_id` is populated after the experiment is provisioned; poll `GET /v2/task-runs/{run_id}` until `status` reaches a terminal state.
""" # noqa: E501
id: StrictStr = Field(description="The unique identifier for the task run.")
task_id: StrictStr = Field(description="The parent task global ID (base64).")
experiment_id: Optional[StrictStr] = Field(default=None, description="Created experiment global ID (base64). Present only for `run_experiment` task runs; null for all other task types. ")
status: StrictStr = Field(description="The current status of the run.")
run_started_at: Optional[datetime] = Field(description="When the run started processing.")
run_finished_at: Optional[datetime] = Field(description="When the run finished processing.")
data_start_time: Optional[datetime] = Field(description="Start of the data window evaluated. Null for run_experiment runs.")
data_end_time: Optional[datetime] = Field(description="End of the data window evaluated. Null for run_experiment runs.")
num_successes: StrictInt = Field(description="Number of successfully evaluated items.")
num_errors: StrictInt = Field(description="Number of items that errored during evaluation.")
num_skipped: StrictInt = Field(description="Number of items that were skipped.")
created_at: datetime = Field(description="When the run was created.")
created_by_user_id: Optional[StrictStr] = Field(description="The unique identifier for the user who triggered the run.")
__properties: ClassVar[List[str]] = ["id", "task_id", "experiment_id", "status", "run_started_at", "run_finished_at", "data_start_time", "data_end_time", "num_successes", "num_errors", "num_skipped", "created_at", "created_by_user_id"]
[docs]
@field_validator('status')
def status_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(['pending', 'running', 'completed', 'failed', 'cancelled']):
raise ValueError("must be one of enum values ('pending', 'running', 'completed', 'failed', 'cancelled')")
return value
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
[docs]
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
[docs]
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())
[docs]
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of TaskRun from a JSON string"""
return cls.from_dict(json.loads(json_str))
[docs]
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,
)
# set to None if experiment_id (nullable) is None
# and model_fields_set contains the field
if self.experiment_id is None and "experiment_id" in self.model_fields_set:
_dict['experiment_id'] = None
# set to None if run_started_at (nullable) is None
# and model_fields_set contains the field
if self.run_started_at is None and "run_started_at" in self.model_fields_set:
_dict['run_started_at'] = None
# set to None if run_finished_at (nullable) is None
# and model_fields_set contains the field
if self.run_finished_at is None and "run_finished_at" in self.model_fields_set:
_dict['run_finished_at'] = None
# set to None if data_start_time (nullable) is None
# and model_fields_set contains the field
if self.data_start_time is None and "data_start_time" in self.model_fields_set:
_dict['data_start_time'] = None
# set to None if data_end_time (nullable) is None
# and model_fields_set contains the field
if self.data_end_time is None and "data_end_time" in self.model_fields_set:
_dict['data_end_time'] = None
# set to None if created_by_user_id (nullable) is None
# and model_fields_set contains the field
if self.created_by_user_id is None and "created_by_user_id" in self.model_fields_set:
_dict['created_by_user_id'] = None
return _dict
[docs]
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TaskRun from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
# raise errors for additional fields in the input
for _key in obj.keys():
if _key not in cls.__properties:
raise ValueError("Error due to additional fields (not defined in TaskRun) in the input: " + _key)
_obj = cls.model_validate({
"id": obj.get("id"),
"task_id": obj.get("task_id"),
"experiment_id": obj.get("experiment_id"),
"status": obj.get("status"),
"run_started_at": obj.get("run_started_at"),
"run_finished_at": obj.get("run_finished_at"),
"data_start_time": obj.get("data_start_time"),
"data_end_time": obj.get("data_end_time"),
"num_successes": obj.get("num_successes"),
"num_errors": obj.get("num_errors"),
"num_skipped": obj.get("num_skipped"),
"created_at": obj.get("created_at"),
"created_by_user_id": obj.get("created_by_user_id")
})
return _obj