Source code for arize._generated.api_client.models.managed_code_config
# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from arize._generated.api_client.models.data_granularity import DataGranularity
from arize._generated.api_client.models.managed_code_evaluator import ManagedCodeEvaluator
from arize._generated.api_client.models.static_param import StaticParam
from typing import Optional, Set
from typing_extensions import Self
[docs]
class ManagedCodeConfig(BaseModel):
"""
ManagedCodeConfig
""" # noqa: E501
data_granularity: Optional[DataGranularity] = Field(default=None, description="Data granularity level for evaluation. When omitted or null, no granularity filter is applied (span-level evaluation is used by default on the server). ")
query_filter: Optional[StrictStr] = Field(default=None, description="Optional filter query over the chosen data granularity. When omitted or null, no filter is applied. ")
type: StrictStr = Field(description="Discriminator identifying this as a managed (built-in) code evaluator")
name: Annotated[str, Field(strict=True)] = Field(description="Eval column name. Must match ^[a-zA-Z0-9_\\s\\-&()]+$")
managed_evaluator: ManagedCodeEvaluator
variables: List[StrictStr] = Field(description="Dataset columns or span attributes passed into the evaluator (order and count must match the managed evaluator's requirements). ")
static_params: Optional[List[StaticParam]] = Field(default=None, description="Static parameters for the managed evaluator (see registry `args`). When omitted, the registry's required arguments must be satisfied by defaults on the evaluator class; otherwise validation fails with 400. If the registry has no args, omitting this field is equivalent to an empty list. ")
__properties: ClassVar[List[str]] = ["data_granularity", "query_filter", "type", "name", "managed_evaluator", "variables", "static_params"]
[docs]
@field_validator('type')
def type_validate_enum(cls, value):
"""Validates the enum"""
if value not in set(['managed']):
raise ValueError("must be one of enum values ('managed')")
return value
[docs]
@field_validator('name')
def name_validate_regular_expression(cls, value):
"""Validates the regular expression"""
if not re.match(r"^[a-zA-Z0-9_\s\-&()]+$", value):
raise ValueError(r"must validate the regular expression /^[a-zA-Z0-9_\s\-&()]+$/")
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 ManagedCodeConfig 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,
)
# override the default output from pydantic by calling `to_dict()` of each item in static_params (list)
_items = []
if self.static_params:
for _item_static_params in self.static_params:
if _item_static_params:
_items.append(_item_static_params.to_dict())
_dict['static_params'] = _items
# set to None if data_granularity (nullable) is None
# and model_fields_set contains the field
if self.data_granularity is None and "data_granularity" in self.model_fields_set:
_dict['data_granularity'] = None
# set to None if query_filter (nullable) is None
# and model_fields_set contains the field
if self.query_filter is None and "query_filter" in self.model_fields_set:
_dict['query_filter'] = None
return _dict
[docs]
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ManagedCodeConfig 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 ManagedCodeConfig) in the input: " + _key)
_obj = cls.model_validate({
"data_granularity": obj.get("data_granularity"),
"query_filter": obj.get("query_filter"),
"type": obj.get("type"),
"name": obj.get("name"),
"managed_evaluator": obj.get("managed_evaluator"),
"variables": obj.get("variables"),
"static_params": [StaticParam.from_dict(_item) for _item in obj["static_params"]] if obj.get("static_params") is not None else None
})
return _obj