|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
6 | | -from typing import Any, Mapping |
| 6 | +from typing import TYPE_CHECKING, Any, Mapping |
7 | 7 | from typing_extensions import Self, override |
8 | 8 |
|
9 | 9 | import httpx |
|
20 | 20 | not_given, |
21 | 21 | ) |
22 | 22 | from ._utils import is_given, get_async_library |
| 23 | +from ._compat import cached_property |
23 | 24 | from ._version import __version__ |
24 | | -from .resources import embeddings, rerankings |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream |
26 | 26 | from ._exceptions import IsaacusError, APIStatusError |
27 | 27 | from ._base_client import ( |
28 | 28 | DEFAULT_MAX_RETRIES, |
29 | 29 | SyncAPIClient, |
30 | 30 | AsyncAPIClient, |
31 | 31 | ) |
32 | | -from .resources.extractions import extractions |
33 | | -from .resources.classifications import classifications |
| 32 | + |
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import embeddings, rerankings, extractions, classifications |
| 35 | + from .resources.embeddings import EmbeddingsResource, AsyncEmbeddingsResource |
| 36 | + from .resources.rerankings import RerankingsResource, AsyncRerankingsResource |
| 37 | + from .resources.extractions.extractions import ExtractionsResource, AsyncExtractionsResource |
| 38 | + from .resources.classifications.classifications import ClassificationsResource, AsyncClassificationsResource |
34 | 39 |
|
35 | 40 | __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Isaacus", "AsyncIsaacus", "Client", "AsyncClient"] |
36 | 41 |
|
37 | 42 |
|
38 | 43 | class Isaacus(SyncAPIClient): |
39 | | - embeddings: embeddings.EmbeddingsResource |
40 | | - classifications: classifications.ClassificationsResource |
41 | | - rerankings: rerankings.RerankingsResource |
42 | | - extractions: extractions.ExtractionsResource |
43 | | - with_raw_response: IsaacusWithRawResponse |
44 | | - with_streaming_response: IsaacusWithStreamedResponse |
45 | | - |
46 | 44 | # client options |
47 | 45 | api_key: str |
48 | 46 |
|
@@ -97,12 +95,37 @@ def __init__( |
97 | 95 | _strict_response_validation=_strict_response_validation, |
98 | 96 | ) |
99 | 97 |
|
100 | | - self.embeddings = embeddings.EmbeddingsResource(self) |
101 | | - self.classifications = classifications.ClassificationsResource(self) |
102 | | - self.rerankings = rerankings.RerankingsResource(self) |
103 | | - self.extractions = extractions.ExtractionsResource(self) |
104 | | - self.with_raw_response = IsaacusWithRawResponse(self) |
105 | | - self.with_streaming_response = IsaacusWithStreamedResponse(self) |
| 98 | + @cached_property |
| 99 | + def embeddings(self) -> EmbeddingsResource: |
| 100 | + from .resources.embeddings import EmbeddingsResource |
| 101 | + |
| 102 | + return EmbeddingsResource(self) |
| 103 | + |
| 104 | + @cached_property |
| 105 | + def classifications(self) -> ClassificationsResource: |
| 106 | + from .resources.classifications import ClassificationsResource |
| 107 | + |
| 108 | + return ClassificationsResource(self) |
| 109 | + |
| 110 | + @cached_property |
| 111 | + def rerankings(self) -> RerankingsResource: |
| 112 | + from .resources.rerankings import RerankingsResource |
| 113 | + |
| 114 | + return RerankingsResource(self) |
| 115 | + |
| 116 | + @cached_property |
| 117 | + def extractions(self) -> ExtractionsResource: |
| 118 | + from .resources.extractions import ExtractionsResource |
| 119 | + |
| 120 | + return ExtractionsResource(self) |
| 121 | + |
| 122 | + @cached_property |
| 123 | + def with_raw_response(self) -> IsaacusWithRawResponse: |
| 124 | + return IsaacusWithRawResponse(self) |
| 125 | + |
| 126 | + @cached_property |
| 127 | + def with_streaming_response(self) -> IsaacusWithStreamedResponse: |
| 128 | + return IsaacusWithStreamedResponse(self) |
106 | 129 |
|
107 | 130 | @property |
108 | 131 | @override |
@@ -210,13 +233,6 @@ def _make_status_error( |
210 | 233 |
|
211 | 234 |
|
212 | 235 | class AsyncIsaacus(AsyncAPIClient): |
213 | | - embeddings: embeddings.AsyncEmbeddingsResource |
214 | | - classifications: classifications.AsyncClassificationsResource |
215 | | - rerankings: rerankings.AsyncRerankingsResource |
216 | | - extractions: extractions.AsyncExtractionsResource |
217 | | - with_raw_response: AsyncIsaacusWithRawResponse |
218 | | - with_streaming_response: AsyncIsaacusWithStreamedResponse |
219 | | - |
220 | 236 | # client options |
221 | 237 | api_key: str |
222 | 238 |
|
@@ -271,12 +287,37 @@ def __init__( |
271 | 287 | _strict_response_validation=_strict_response_validation, |
272 | 288 | ) |
273 | 289 |
|
274 | | - self.embeddings = embeddings.AsyncEmbeddingsResource(self) |
275 | | - self.classifications = classifications.AsyncClassificationsResource(self) |
276 | | - self.rerankings = rerankings.AsyncRerankingsResource(self) |
277 | | - self.extractions = extractions.AsyncExtractionsResource(self) |
278 | | - self.with_raw_response = AsyncIsaacusWithRawResponse(self) |
279 | | - self.with_streaming_response = AsyncIsaacusWithStreamedResponse(self) |
| 290 | + @cached_property |
| 291 | + def embeddings(self) -> AsyncEmbeddingsResource: |
| 292 | + from .resources.embeddings import AsyncEmbeddingsResource |
| 293 | + |
| 294 | + return AsyncEmbeddingsResource(self) |
| 295 | + |
| 296 | + @cached_property |
| 297 | + def classifications(self) -> AsyncClassificationsResource: |
| 298 | + from .resources.classifications import AsyncClassificationsResource |
| 299 | + |
| 300 | + return AsyncClassificationsResource(self) |
| 301 | + |
| 302 | + @cached_property |
| 303 | + def rerankings(self) -> AsyncRerankingsResource: |
| 304 | + from .resources.rerankings import AsyncRerankingsResource |
| 305 | + |
| 306 | + return AsyncRerankingsResource(self) |
| 307 | + |
| 308 | + @cached_property |
| 309 | + def extractions(self) -> AsyncExtractionsResource: |
| 310 | + from .resources.extractions import AsyncExtractionsResource |
| 311 | + |
| 312 | + return AsyncExtractionsResource(self) |
| 313 | + |
| 314 | + @cached_property |
| 315 | + def with_raw_response(self) -> AsyncIsaacusWithRawResponse: |
| 316 | + return AsyncIsaacusWithRawResponse(self) |
| 317 | + |
| 318 | + @cached_property |
| 319 | + def with_streaming_response(self) -> AsyncIsaacusWithStreamedResponse: |
| 320 | + return AsyncIsaacusWithStreamedResponse(self) |
280 | 321 |
|
281 | 322 | @property |
282 | 323 | @override |
@@ -384,35 +425,127 @@ def _make_status_error( |
384 | 425 |
|
385 | 426 |
|
386 | 427 | class IsaacusWithRawResponse: |
| 428 | + _client: Isaacus |
| 429 | + |
387 | 430 | def __init__(self, client: Isaacus) -> None: |
388 | | - self.embeddings = embeddings.EmbeddingsResourceWithRawResponse(client.embeddings) |
389 | | - self.classifications = classifications.ClassificationsResourceWithRawResponse(client.classifications) |
390 | | - self.rerankings = rerankings.RerankingsResourceWithRawResponse(client.rerankings) |
391 | | - self.extractions = extractions.ExtractionsResourceWithRawResponse(client.extractions) |
| 431 | + self._client = client |
| 432 | + |
| 433 | + @cached_property |
| 434 | + def embeddings(self) -> embeddings.EmbeddingsResourceWithRawResponse: |
| 435 | + from .resources.embeddings import EmbeddingsResourceWithRawResponse |
| 436 | + |
| 437 | + return EmbeddingsResourceWithRawResponse(self._client.embeddings) |
| 438 | + |
| 439 | + @cached_property |
| 440 | + def classifications(self) -> classifications.ClassificationsResourceWithRawResponse: |
| 441 | + from .resources.classifications import ClassificationsResourceWithRawResponse |
| 442 | + |
| 443 | + return ClassificationsResourceWithRawResponse(self._client.classifications) |
| 444 | + |
| 445 | + @cached_property |
| 446 | + def rerankings(self) -> rerankings.RerankingsResourceWithRawResponse: |
| 447 | + from .resources.rerankings import RerankingsResourceWithRawResponse |
| 448 | + |
| 449 | + return RerankingsResourceWithRawResponse(self._client.rerankings) |
| 450 | + |
| 451 | + @cached_property |
| 452 | + def extractions(self) -> extractions.ExtractionsResourceWithRawResponse: |
| 453 | + from .resources.extractions import ExtractionsResourceWithRawResponse |
| 454 | + |
| 455 | + return ExtractionsResourceWithRawResponse(self._client.extractions) |
392 | 456 |
|
393 | 457 |
|
394 | 458 | class AsyncIsaacusWithRawResponse: |
| 459 | + _client: AsyncIsaacus |
| 460 | + |
395 | 461 | def __init__(self, client: AsyncIsaacus) -> None: |
396 | | - self.embeddings = embeddings.AsyncEmbeddingsResourceWithRawResponse(client.embeddings) |
397 | | - self.classifications = classifications.AsyncClassificationsResourceWithRawResponse(client.classifications) |
398 | | - self.rerankings = rerankings.AsyncRerankingsResourceWithRawResponse(client.rerankings) |
399 | | - self.extractions = extractions.AsyncExtractionsResourceWithRawResponse(client.extractions) |
| 462 | + self._client = client |
| 463 | + |
| 464 | + @cached_property |
| 465 | + def embeddings(self) -> embeddings.AsyncEmbeddingsResourceWithRawResponse: |
| 466 | + from .resources.embeddings import AsyncEmbeddingsResourceWithRawResponse |
| 467 | + |
| 468 | + return AsyncEmbeddingsResourceWithRawResponse(self._client.embeddings) |
| 469 | + |
| 470 | + @cached_property |
| 471 | + def classifications(self) -> classifications.AsyncClassificationsResourceWithRawResponse: |
| 472 | + from .resources.classifications import AsyncClassificationsResourceWithRawResponse |
| 473 | + |
| 474 | + return AsyncClassificationsResourceWithRawResponse(self._client.classifications) |
| 475 | + |
| 476 | + @cached_property |
| 477 | + def rerankings(self) -> rerankings.AsyncRerankingsResourceWithRawResponse: |
| 478 | + from .resources.rerankings import AsyncRerankingsResourceWithRawResponse |
| 479 | + |
| 480 | + return AsyncRerankingsResourceWithRawResponse(self._client.rerankings) |
| 481 | + |
| 482 | + @cached_property |
| 483 | + def extractions(self) -> extractions.AsyncExtractionsResourceWithRawResponse: |
| 484 | + from .resources.extractions import AsyncExtractionsResourceWithRawResponse |
| 485 | + |
| 486 | + return AsyncExtractionsResourceWithRawResponse(self._client.extractions) |
400 | 487 |
|
401 | 488 |
|
402 | 489 | class IsaacusWithStreamedResponse: |
| 490 | + _client: Isaacus |
| 491 | + |
403 | 492 | def __init__(self, client: Isaacus) -> None: |
404 | | - self.embeddings = embeddings.EmbeddingsResourceWithStreamingResponse(client.embeddings) |
405 | | - self.classifications = classifications.ClassificationsResourceWithStreamingResponse(client.classifications) |
406 | | - self.rerankings = rerankings.RerankingsResourceWithStreamingResponse(client.rerankings) |
407 | | - self.extractions = extractions.ExtractionsResourceWithStreamingResponse(client.extractions) |
| 493 | + self._client = client |
| 494 | + |
| 495 | + @cached_property |
| 496 | + def embeddings(self) -> embeddings.EmbeddingsResourceWithStreamingResponse: |
| 497 | + from .resources.embeddings import EmbeddingsResourceWithStreamingResponse |
| 498 | + |
| 499 | + return EmbeddingsResourceWithStreamingResponse(self._client.embeddings) |
| 500 | + |
| 501 | + @cached_property |
| 502 | + def classifications(self) -> classifications.ClassificationsResourceWithStreamingResponse: |
| 503 | + from .resources.classifications import ClassificationsResourceWithStreamingResponse |
| 504 | + |
| 505 | + return ClassificationsResourceWithStreamingResponse(self._client.classifications) |
| 506 | + |
| 507 | + @cached_property |
| 508 | + def rerankings(self) -> rerankings.RerankingsResourceWithStreamingResponse: |
| 509 | + from .resources.rerankings import RerankingsResourceWithStreamingResponse |
| 510 | + |
| 511 | + return RerankingsResourceWithStreamingResponse(self._client.rerankings) |
| 512 | + |
| 513 | + @cached_property |
| 514 | + def extractions(self) -> extractions.ExtractionsResourceWithStreamingResponse: |
| 515 | + from .resources.extractions import ExtractionsResourceWithStreamingResponse |
| 516 | + |
| 517 | + return ExtractionsResourceWithStreamingResponse(self._client.extractions) |
408 | 518 |
|
409 | 519 |
|
410 | 520 | class AsyncIsaacusWithStreamedResponse: |
| 521 | + _client: AsyncIsaacus |
| 522 | + |
411 | 523 | def __init__(self, client: AsyncIsaacus) -> None: |
412 | | - self.embeddings = embeddings.AsyncEmbeddingsResourceWithStreamingResponse(client.embeddings) |
413 | | - self.classifications = classifications.AsyncClassificationsResourceWithStreamingResponse(client.classifications) |
414 | | - self.rerankings = rerankings.AsyncRerankingsResourceWithStreamingResponse(client.rerankings) |
415 | | - self.extractions = extractions.AsyncExtractionsResourceWithStreamingResponse(client.extractions) |
| 524 | + self._client = client |
| 525 | + |
| 526 | + @cached_property |
| 527 | + def embeddings(self) -> embeddings.AsyncEmbeddingsResourceWithStreamingResponse: |
| 528 | + from .resources.embeddings import AsyncEmbeddingsResourceWithStreamingResponse |
| 529 | + |
| 530 | + return AsyncEmbeddingsResourceWithStreamingResponse(self._client.embeddings) |
| 531 | + |
| 532 | + @cached_property |
| 533 | + def classifications(self) -> classifications.AsyncClassificationsResourceWithStreamingResponse: |
| 534 | + from .resources.classifications import AsyncClassificationsResourceWithStreamingResponse |
| 535 | + |
| 536 | + return AsyncClassificationsResourceWithStreamingResponse(self._client.classifications) |
| 537 | + |
| 538 | + @cached_property |
| 539 | + def rerankings(self) -> rerankings.AsyncRerankingsResourceWithStreamingResponse: |
| 540 | + from .resources.rerankings import AsyncRerankingsResourceWithStreamingResponse |
| 541 | + |
| 542 | + return AsyncRerankingsResourceWithStreamingResponse(self._client.rerankings) |
| 543 | + |
| 544 | + @cached_property |
| 545 | + def extractions(self) -> extractions.AsyncExtractionsResourceWithStreamingResponse: |
| 546 | + from .resources.extractions import AsyncExtractionsResourceWithStreamingResponse |
| 547 | + |
| 548 | + return AsyncExtractionsResourceWithStreamingResponse(self._client.extractions) |
416 | 549 |
|
417 | 550 |
|
418 | 551 | Client = Isaacus |
|
0 commit comments