|
| 1 | +# (C) 2024 GoodData Corporation |
| 2 | +from __future__ import annotations |
| 3 | + |
| 4 | +from typing import Any, Optional |
| 5 | + |
| 6 | +from attr import define |
| 7 | +from gooddata_api_client.model.json_api_llm_endpoint_in import JsonApiLlmEndpointIn |
| 8 | +from gooddata_api_client.model.json_api_llm_endpoint_in_attributes import JsonApiLlmEndpointInAttributes |
| 9 | +from gooddata_api_client.model.json_api_llm_endpoint_in_document import JsonApiLlmEndpointInDocument |
| 10 | +from gooddata_api_client.model.json_api_llm_endpoint_patch import JsonApiLlmEndpointPatch |
| 11 | +from gooddata_api_client.model.json_api_llm_endpoint_patch_attributes import JsonApiLlmEndpointPatchAttributes |
| 12 | +from gooddata_api_client.model.json_api_llm_endpoint_patch_document import JsonApiLlmEndpointPatchDocument |
| 13 | + |
| 14 | +from gooddata_sdk.catalog.base import Base |
| 15 | +from gooddata_sdk.utils import safeget |
| 16 | + |
| 17 | + |
| 18 | +@define(kw_only=True) |
| 19 | +class CatalogLlmEndpointDocument(Base): |
| 20 | + data: CatalogLlmEndpoint |
| 21 | + |
| 22 | + @staticmethod |
| 23 | + def client_class() -> type[JsonApiLlmEndpointInDocument]: |
| 24 | + return JsonApiLlmEndpointInDocument |
| 25 | + |
| 26 | + |
| 27 | +@define(kw_only=True) |
| 28 | +class CatalogLlmEndpointPatchDocument(Base): |
| 29 | + data: CatalogLlmEndpointPatch |
| 30 | + |
| 31 | + @staticmethod |
| 32 | + def client_class() -> type[JsonApiLlmEndpointPatchDocument]: |
| 33 | + return JsonApiLlmEndpointPatchDocument |
| 34 | + |
| 35 | + |
| 36 | +@define(kw_only=True) |
| 37 | +class CatalogLlmEndpoint(Base): |
| 38 | + id: str |
| 39 | + attributes: Optional[CatalogLlmEndpointAttributes] = None |
| 40 | + |
| 41 | + @staticmethod |
| 42 | + def client_class() -> type[JsonApiLlmEndpointIn]: |
| 43 | + return JsonApiLlmEndpointIn |
| 44 | + |
| 45 | + @classmethod |
| 46 | + def init( |
| 47 | + cls, |
| 48 | + id: str, |
| 49 | + title: str, |
| 50 | + token: str, |
| 51 | + description: Optional[str] = None, |
| 52 | + provider: Optional[str] = None, |
| 53 | + base_url: Optional[str] = None, |
| 54 | + llm_organization: Optional[str] = None, |
| 55 | + llm_model: Optional[str] = None, |
| 56 | + workspace_ids: Optional[list[str]] = None, |
| 57 | + ) -> CatalogLlmEndpoint: |
| 58 | + return cls( |
| 59 | + id=id, |
| 60 | + attributes=CatalogLlmEndpointAttributes( |
| 61 | + title=title, |
| 62 | + token=token, |
| 63 | + description=description, |
| 64 | + provider=provider, |
| 65 | + base_url=base_url, |
| 66 | + llm_organization=llm_organization, |
| 67 | + llm_model=llm_model, |
| 68 | + workspace_ids=workspace_ids, |
| 69 | + ), |
| 70 | + ) |
| 71 | + |
| 72 | + @classmethod |
| 73 | + def from_api(cls, entity: dict[str, Any]) -> CatalogLlmEndpoint: |
| 74 | + ea = entity["attributes"] |
| 75 | + attr = CatalogLlmEndpointAttributes( |
| 76 | + title=safeget(ea, ["title"]), |
| 77 | + token=None, # Token is not returned for security reasons |
| 78 | + description=safeget(ea, ["description"]), |
| 79 | + provider=safeget(ea, ["provider"]), |
| 80 | + base_url=safeget(ea, ["baseUrl"]), |
| 81 | + llm_organization=safeget(ea, ["llmOrganization"]), |
| 82 | + llm_model=safeget(ea, ["llmModel"]), |
| 83 | + workspace_ids=safeget(ea, ["workspaceIds"]), |
| 84 | + ) |
| 85 | + return cls( |
| 86 | + id=entity["id"], |
| 87 | + attributes=attr, |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +@define(kw_only=True) |
| 92 | +class CatalogLlmEndpointPatch(Base): |
| 93 | + id: str |
| 94 | + attributes: Optional[CatalogLlmEndpointPatchAttributes] = None |
| 95 | + |
| 96 | + @staticmethod |
| 97 | + def client_class() -> type[JsonApiLlmEndpointPatch]: |
| 98 | + return JsonApiLlmEndpointPatch |
| 99 | + |
| 100 | + @classmethod |
| 101 | + def init( |
| 102 | + cls, |
| 103 | + id: str, |
| 104 | + title: Optional[str] = None, |
| 105 | + token: Optional[str] = None, |
| 106 | + description: Optional[str] = None, |
| 107 | + provider: Optional[str] = None, |
| 108 | + base_url: Optional[str] = None, |
| 109 | + llm_organization: Optional[str] = None, |
| 110 | + llm_model: Optional[str] = None, |
| 111 | + workspace_ids: Optional[list[str]] = None, |
| 112 | + ) -> CatalogLlmEndpointPatch: |
| 113 | + return cls( |
| 114 | + id=id, |
| 115 | + attributes=CatalogLlmEndpointPatchAttributes( |
| 116 | + title=title, |
| 117 | + token=token, |
| 118 | + description=description, |
| 119 | + provider=provider, |
| 120 | + base_url=base_url, |
| 121 | + llm_organization=llm_organization, |
| 122 | + llm_model=llm_model, |
| 123 | + workspace_ids=workspace_ids, |
| 124 | + ), |
| 125 | + ) |
| 126 | + |
| 127 | + |
| 128 | +@define(kw_only=True) |
| 129 | +class CatalogLlmEndpointAttributes(Base): |
| 130 | + title: str |
| 131 | + token: str |
| 132 | + description: Optional[str] = None |
| 133 | + provider: Optional[str] = None |
| 134 | + base_url: Optional[str] = None |
| 135 | + llm_organization: Optional[str] = None |
| 136 | + llm_model: Optional[str] = None |
| 137 | + workspace_ids: Optional[list[str]] = None |
| 138 | + |
| 139 | + @staticmethod |
| 140 | + def client_class() -> type[JsonApiLlmEndpointInAttributes]: |
| 141 | + return JsonApiLlmEndpointInAttributes |
| 142 | + |
| 143 | + def to_api(self) -> dict: |
| 144 | + """Convert to API format (camelCase). Only include non-None attributes.""" |
| 145 | + result = { |
| 146 | + "title": self.title, |
| 147 | + "token": self.token, |
| 148 | + } |
| 149 | + if self.description is not None: |
| 150 | + result["description"] = self.description |
| 151 | + if self.provider is not None: |
| 152 | + result["provider"] = self.provider |
| 153 | + if self.base_url is not None: |
| 154 | + result["baseUrl"] = self.base_url |
| 155 | + if self.llm_organization is not None: |
| 156 | + result["llmOrganization"] = self.llm_organization |
| 157 | + if self.llm_model is not None: |
| 158 | + result["llmModel"] = self.llm_model |
| 159 | + if self.workspace_ids is not None: |
| 160 | + result["workspaceIds"] = self.workspace_ids |
| 161 | + return result |
| 162 | + |
| 163 | + def to_dict(self) -> dict: |
| 164 | + """Convert to dictionary format. Only include non-None attributes.""" |
| 165 | + result = { |
| 166 | + "title": self.title, |
| 167 | + "token": self.token, |
| 168 | + } |
| 169 | + if self.description is not None: |
| 170 | + result["description"] = self.description |
| 171 | + if self.provider is not None: |
| 172 | + result["provider"] = self.provider |
| 173 | + if self.base_url is not None: |
| 174 | + result["baseUrl"] = self.base_url |
| 175 | + if self.llm_organization is not None: |
| 176 | + result["llmOrganization"] = self.llm_organization |
| 177 | + if self.llm_model is not None: |
| 178 | + result["llmModel"] = self.llm_model |
| 179 | + if self.workspace_ids is not None: |
| 180 | + result["workspaceIds"] = self.workspace_ids |
| 181 | + return result |
| 182 | + |
| 183 | + |
| 184 | +@define(kw_only=True) |
| 185 | +class CatalogLlmEndpointPatchAttributes(Base): |
| 186 | + title: Optional[str] = None |
| 187 | + token: Optional[str] = None |
| 188 | + description: Optional[str] = None |
| 189 | + provider: Optional[str] = None |
| 190 | + base_url: Optional[str] = None |
| 191 | + llm_organization: Optional[str] = None |
| 192 | + llm_model: Optional[str] = None |
| 193 | + workspace_ids: Optional[list[str]] = None |
| 194 | + |
| 195 | + @staticmethod |
| 196 | + def client_class() -> type[JsonApiLlmEndpointPatchAttributes]: |
| 197 | + return JsonApiLlmEndpointPatchAttributes |
| 198 | + |
| 199 | + def to_api(self) -> dict: |
| 200 | + """Convert to API format (camelCase). Only include non-None attributes.""" |
| 201 | + result = {} |
| 202 | + if self.title is not None: |
| 203 | + result["title"] = self.title |
| 204 | + if self.token is not None: |
| 205 | + result["token"] = self.token |
| 206 | + if self.description is not None: |
| 207 | + result["description"] = self.description |
| 208 | + if self.provider is not None: |
| 209 | + result["provider"] = self.provider |
| 210 | + if self.base_url is not None: |
| 211 | + result["baseUrl"] = self.base_url |
| 212 | + if self.llm_organization is not None: |
| 213 | + result["llmOrganization"] = self.llm_organization |
| 214 | + if self.llm_model is not None: |
| 215 | + result["llmModel"] = self.llm_model |
| 216 | + if self.workspace_ids is not None: |
| 217 | + result["workspaceIds"] = self.workspace_ids |
| 218 | + return result |
| 219 | + |
| 220 | + def to_dict(self) -> dict: |
| 221 | + """Convert to dictionary format. Only include non-None attributes.""" |
| 222 | + result = {} |
| 223 | + if self.title is not None: |
| 224 | + result["title"] = self.title |
| 225 | + if self.token is not None: |
| 226 | + result["token"] = self.token |
| 227 | + if self.description is not None: |
| 228 | + result["description"] = self.description |
| 229 | + if self.provider is not None: |
| 230 | + result["provider"] = self.provider |
| 231 | + if self.base_url is not None: |
| 232 | + result["baseUrl"] = self.base_url |
| 233 | + if self.llm_organization is not None: |
| 234 | + result["llmOrganization"] = self.llm_organization |
| 235 | + if self.llm_model is not None: |
| 236 | + result["llmModel"] = self.llm_model |
| 237 | + if self.workspace_ids is not None: |
| 238 | + result["workspaceIds"] = self.workspace_ids |
| 239 | + return result |
0 commit comments