# 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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from arize._generated.api_client.models.ai_integration_auth_type import AiIntegrationAuthType
from arize._generated.api_client.models.ai_integration_provider import AiIntegrationProvider
from arize._generated.api_client.models.ai_integration_provider_metadata import AiIntegrationProviderMetadata
from arize._generated.api_client.models.ai_integration_scoping import AiIntegrationScoping
from typing import Optional, Set
from typing_extensions import Self
[docs]
class AiIntegration(BaseModel):
"""
An AI integration configures access to an external LLM provider (e.g. OpenAI, Azure OpenAI, AWS Bedrock, Vertex AI). Integrations can be scoped to the entire account, a specific organization, or a specific space.
""" # noqa: E501
id: StrictStr = Field(description="The integration ID")
name: StrictStr = Field(description="The integration name")
provider: AiIntegrationProvider
has_api_key: StrictBool = Field(description="Whether an API key is configured (the key itself is never returned)")
base_url: Optional[StrictStr] = Field(default=None, description="Custom base URL for the provider")
model_names: Optional[List[StrictStr]] = Field(default=None, description="Supported model names")
headers: Optional[Dict[str, StrictStr]] = Field(default=None, description="Custom headers included in requests")
enable_default_models: StrictBool = Field(description="Whether the provider's default model list is enabled")
function_calling_enabled: StrictBool = Field(description="Whether function/tool calling is enabled")
auth_type: AiIntegrationAuthType
provider_metadata: Optional[AiIntegrationProviderMetadata] = None
scopings: List[AiIntegrationScoping] = Field(description="Visibility scoping rules")
created_at: datetime = Field(description="When the integration was created")
updated_at: datetime = Field(description="When the integration was last updated")
created_by_user_id: StrictStr = Field(description="The user ID of the user who created the integration")
__properties: ClassVar[List[str]] = ["id", "name", "provider", "has_api_key", "base_url", "model_names", "headers", "enable_default_models", "function_calling_enabled", "auth_type", "provider_metadata", "scopings", "created_at", "updated_at", "created_by_user_id"]
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 AiIntegration 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 provider_metadata
if self.provider_metadata:
_dict['provider_metadata'] = self.provider_metadata.to_dict()
# override the default output from pydantic by calling `to_dict()` of each item in scopings (list)
_items = []
if self.scopings:
for _item_scopings in self.scopings:
if _item_scopings:
_items.append(_item_scopings.to_dict())
_dict['scopings'] = _items
# set to None if base_url (nullable) is None
# and model_fields_set contains the field
if self.base_url is None and "base_url" in self.model_fields_set:
_dict['base_url'] = None
# set to None if model_names (nullable) is None
# and model_fields_set contains the field
if self.model_names is None and "model_names" in self.model_fields_set:
_dict['model_names'] = None
# set to None if headers (nullable) is None
# and model_fields_set contains the field
if self.headers is None and "headers" in self.model_fields_set:
_dict['headers'] = None
# set to None if provider_metadata (nullable) is None
# and model_fields_set contains the field
if self.provider_metadata is None and "provider_metadata" in self.model_fields_set:
_dict['provider_metadata'] = None
return _dict
[docs]
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AiIntegration 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 AiIntegration) in the input: " + _key)
_obj = cls.model_validate({
"id": obj.get("id"),
"name": obj.get("name"),
"provider": obj.get("provider"),
"has_api_key": obj.get("has_api_key"),
"base_url": obj.get("base_url"),
"model_names": obj.get("model_names"),
"headers": obj.get("headers"),
"enable_default_models": obj.get("enable_default_models"),
"function_calling_enabled": obj.get("function_calling_enabled"),
"auth_type": obj.get("auth_type"),
"provider_metadata": AiIntegrationProviderMetadata.from_dict(obj["provider_metadata"]) if obj.get("provider_metadata") is not None else None,
"scopings": [AiIntegrationScoping.from_dict(_item) for _item in obj["scopings"]] if obj.get("scopings") is not None else None,
"created_at": obj.get("created_at"),
"updated_at": obj.get("updated_at"),
"created_by_user_id": obj.get("created_by_user_id")
})
return _obj