Source code for arize._generated.api_client.models.custom_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.static_param import StaticParam
from typing import Optional, Set
from typing_extensions import Self

[docs] class CustomCodeConfig(BaseModel): """ CustomCodeConfig """ # 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 custom (user-supplied Python) code evaluator") name: Annotated[str, Field(strict=True)] = Field(description="Eval column name. Must match ^[a-zA-Z0-9_\\s\\-&()]+$") code: StrictStr = Field(description="Python source defining the evaluator class") imports: Optional[StrictStr] = Field(default=None, description="Optional package import block prepended when running the evaluator") variables: List[StrictStr] = Field(description="Dataset columns or span attributes mapped to evaluate() arguments") static_params: Optional[List[StaticParam]] = Field(default=None, description="Optional typed defaults accessible on the evaluator instance. Omit or pass an empty array when the custom class does not read any static parameters. ") __properties: ClassVar[List[str]] = ["data_granularity", "query_filter", "type", "name", "code", "imports", "variables", "static_params"]
[docs] @field_validator('type') def type_validate_enum(cls, value): """Validates the enum""" if value not in set(['custom']): raise ValueError("must be one of enum values ('custom')") 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 CustomCodeConfig 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 # set to None if imports (nullable) is None # and model_fields_set contains the field if self.imports is None and "imports" in self.model_fields_set: _dict['imports'] = None return _dict
[docs] @classmethod def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: """Create an instance of CustomCodeConfig 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 CustomCodeConfig) 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"), "code": obj.get("code"), "imports": obj.get("imports"), "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