|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 | 5 | import os
|
6 |
| -from typing import Any, Union, Mapping |
| 6 | +from typing import TYPE_CHECKING, Any, Union, Mapping |
7 | 7 | from typing_extensions import Self, override
|
8 | 8 |
|
9 | 9 | import httpx
|
|
20 | 20 | RequestOptions,
|
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 files, models, batches, embeddings |
25 | 25 | from ._streaming import Stream as Stream, AsyncStream as AsyncStream
|
26 | 26 | from ._exceptions import GroqError, APIStatusError
|
27 | 27 | from ._base_client import (
|
28 | 28 | DEFAULT_MAX_RETRIES,
|
29 | 29 | SyncAPIClient,
|
30 | 30 | AsyncAPIClient,
|
31 | 31 | )
|
32 |
| -from .resources.chat import chat |
33 |
| -from .resources.audio import audio |
| 32 | + |
| 33 | +if TYPE_CHECKING: |
| 34 | + from .resources import chat, audio, files, models, batches, embeddings |
| 35 | + from .resources.files import Files, AsyncFiles |
| 36 | + from .resources.models import Models, AsyncModels |
| 37 | + from .resources.batches import Batches, AsyncBatches |
| 38 | + from .resources.chat.chat import Chat, AsyncChat |
| 39 | + from .resources.embeddings import Embeddings, AsyncEmbeddings |
| 40 | + from .resources.audio.audio import Audio, AsyncAudio |
34 | 41 |
|
35 | 42 | __all__ = ["Timeout", "Transport", "ProxiesTypes", "RequestOptions", "Groq", "AsyncGroq", "Client", "AsyncClient"]
|
36 | 43 |
|
37 | 44 |
|
38 | 45 | class Groq(SyncAPIClient):
|
39 |
| - chat: chat.Chat |
40 |
| - embeddings: embeddings.Embeddings |
41 |
| - audio: audio.Audio |
42 |
| - models: models.Models |
43 |
| - batches: batches.Batches |
44 |
| - files: files.Files |
45 |
| - with_raw_response: GroqWithRawResponse |
46 |
| - with_streaming_response: GroqWithStreamedResponse |
47 |
| - |
48 | 46 | # client options
|
49 | 47 | api_key: str
|
50 | 48 |
|
@@ -99,14 +97,49 @@ def __init__(
|
99 | 97 | _strict_response_validation=_strict_response_validation,
|
100 | 98 | )
|
101 | 99 |
|
102 |
| - self.chat = chat.Chat(self) |
103 |
| - self.embeddings = embeddings.Embeddings(self) |
104 |
| - self.audio = audio.Audio(self) |
105 |
| - self.models = models.Models(self) |
106 |
| - self.batches = batches.Batches(self) |
107 |
| - self.files = files.Files(self) |
108 |
| - self.with_raw_response = GroqWithRawResponse(self) |
109 |
| - self.with_streaming_response = GroqWithStreamedResponse(self) |
| 100 | + @cached_property |
| 101 | + def chat(self) -> Chat: |
| 102 | + from .resources.chat import Chat |
| 103 | + |
| 104 | + return Chat(self) |
| 105 | + |
| 106 | + @cached_property |
| 107 | + def embeddings(self) -> Embeddings: |
| 108 | + from .resources.embeddings import Embeddings |
| 109 | + |
| 110 | + return Embeddings(self) |
| 111 | + |
| 112 | + @cached_property |
| 113 | + def audio(self) -> Audio: |
| 114 | + from .resources.audio import Audio |
| 115 | + |
| 116 | + return Audio(self) |
| 117 | + |
| 118 | + @cached_property |
| 119 | + def models(self) -> Models: |
| 120 | + from .resources.models import Models |
| 121 | + |
| 122 | + return Models(self) |
| 123 | + |
| 124 | + @cached_property |
| 125 | + def batches(self) -> Batches: |
| 126 | + from .resources.batches import Batches |
| 127 | + |
| 128 | + return Batches(self) |
| 129 | + |
| 130 | + @cached_property |
| 131 | + def files(self) -> Files: |
| 132 | + from .resources.files import Files |
| 133 | + |
| 134 | + return Files(self) |
| 135 | + |
| 136 | + @cached_property |
| 137 | + def with_raw_response(self) -> GroqWithRawResponse: |
| 138 | + return GroqWithRawResponse(self) |
| 139 | + |
| 140 | + @cached_property |
| 141 | + def with_streaming_response(self) -> GroqWithStreamedResponse: |
| 142 | + return GroqWithStreamedResponse(self) |
110 | 143 |
|
111 | 144 | @property
|
112 | 145 | @override
|
@@ -214,15 +247,6 @@ def _make_status_error(
|
214 | 247 |
|
215 | 248 |
|
216 | 249 | class AsyncGroq(AsyncAPIClient):
|
217 |
| - chat: chat.AsyncChat |
218 |
| - embeddings: embeddings.AsyncEmbeddings |
219 |
| - audio: audio.AsyncAudio |
220 |
| - models: models.AsyncModels |
221 |
| - batches: batches.AsyncBatches |
222 |
| - files: files.AsyncFiles |
223 |
| - with_raw_response: AsyncGroqWithRawResponse |
224 |
| - with_streaming_response: AsyncGroqWithStreamedResponse |
225 |
| - |
226 | 250 | # client options
|
227 | 251 | api_key: str
|
228 | 252 |
|
@@ -277,14 +301,49 @@ def __init__(
|
277 | 301 | _strict_response_validation=_strict_response_validation,
|
278 | 302 | )
|
279 | 303 |
|
280 |
| - self.chat = chat.AsyncChat(self) |
281 |
| - self.embeddings = embeddings.AsyncEmbeddings(self) |
282 |
| - self.audio = audio.AsyncAudio(self) |
283 |
| - self.models = models.AsyncModels(self) |
284 |
| - self.batches = batches.AsyncBatches(self) |
285 |
| - self.files = files.AsyncFiles(self) |
286 |
| - self.with_raw_response = AsyncGroqWithRawResponse(self) |
287 |
| - self.with_streaming_response = AsyncGroqWithStreamedResponse(self) |
| 304 | + @cached_property |
| 305 | + def chat(self) -> AsyncChat: |
| 306 | + from .resources.chat import AsyncChat |
| 307 | + |
| 308 | + return AsyncChat(self) |
| 309 | + |
| 310 | + @cached_property |
| 311 | + def embeddings(self) -> AsyncEmbeddings: |
| 312 | + from .resources.embeddings import AsyncEmbeddings |
| 313 | + |
| 314 | + return AsyncEmbeddings(self) |
| 315 | + |
| 316 | + @cached_property |
| 317 | + def audio(self) -> AsyncAudio: |
| 318 | + from .resources.audio import AsyncAudio |
| 319 | + |
| 320 | + return AsyncAudio(self) |
| 321 | + |
| 322 | + @cached_property |
| 323 | + def models(self) -> AsyncModels: |
| 324 | + from .resources.models import AsyncModels |
| 325 | + |
| 326 | + return AsyncModels(self) |
| 327 | + |
| 328 | + @cached_property |
| 329 | + def batches(self) -> AsyncBatches: |
| 330 | + from .resources.batches import AsyncBatches |
| 331 | + |
| 332 | + return AsyncBatches(self) |
| 333 | + |
| 334 | + @cached_property |
| 335 | + def files(self) -> AsyncFiles: |
| 336 | + from .resources.files import AsyncFiles |
| 337 | + |
| 338 | + return AsyncFiles(self) |
| 339 | + |
| 340 | + @cached_property |
| 341 | + def with_raw_response(self) -> AsyncGroqWithRawResponse: |
| 342 | + return AsyncGroqWithRawResponse(self) |
| 343 | + |
| 344 | + @cached_property |
| 345 | + def with_streaming_response(self) -> AsyncGroqWithStreamedResponse: |
| 346 | + return AsyncGroqWithStreamedResponse(self) |
288 | 347 |
|
289 | 348 | @property
|
290 | 349 | @override
|
@@ -392,43 +451,175 @@ def _make_status_error(
|
392 | 451 |
|
393 | 452 |
|
394 | 453 | class GroqWithRawResponse:
|
| 454 | + _client: Groq |
| 455 | + |
395 | 456 | def __init__(self, client: Groq) -> None:
|
396 |
| - self.chat = chat.ChatWithRawResponse(client.chat) |
397 |
| - self.embeddings = embeddings.EmbeddingsWithRawResponse(client.embeddings) |
398 |
| - self.audio = audio.AudioWithRawResponse(client.audio) |
399 |
| - self.models = models.ModelsWithRawResponse(client.models) |
400 |
| - self.batches = batches.BatchesWithRawResponse(client.batches) |
401 |
| - self.files = files.FilesWithRawResponse(client.files) |
| 457 | + self._client = client |
| 458 | + |
| 459 | + @cached_property |
| 460 | + def chat(self) -> chat.ChatWithRawResponse: |
| 461 | + from .resources.chat import ChatWithRawResponse |
| 462 | + |
| 463 | + return ChatWithRawResponse(self._client.chat) |
| 464 | + |
| 465 | + @cached_property |
| 466 | + def embeddings(self) -> embeddings.EmbeddingsWithRawResponse: |
| 467 | + from .resources.embeddings import EmbeddingsWithRawResponse |
| 468 | + |
| 469 | + return EmbeddingsWithRawResponse(self._client.embeddings) |
| 470 | + |
| 471 | + @cached_property |
| 472 | + def audio(self) -> audio.AudioWithRawResponse: |
| 473 | + from .resources.audio import AudioWithRawResponse |
| 474 | + |
| 475 | + return AudioWithRawResponse(self._client.audio) |
| 476 | + |
| 477 | + @cached_property |
| 478 | + def models(self) -> models.ModelsWithRawResponse: |
| 479 | + from .resources.models import ModelsWithRawResponse |
| 480 | + |
| 481 | + return ModelsWithRawResponse(self._client.models) |
| 482 | + |
| 483 | + @cached_property |
| 484 | + def batches(self) -> batches.BatchesWithRawResponse: |
| 485 | + from .resources.batches import BatchesWithRawResponse |
| 486 | + |
| 487 | + return BatchesWithRawResponse(self._client.batches) |
| 488 | + |
| 489 | + @cached_property |
| 490 | + def files(self) -> files.FilesWithRawResponse: |
| 491 | + from .resources.files import FilesWithRawResponse |
| 492 | + |
| 493 | + return FilesWithRawResponse(self._client.files) |
402 | 494 |
|
403 | 495 |
|
404 | 496 | class AsyncGroqWithRawResponse:
|
| 497 | + _client: AsyncGroq |
| 498 | + |
405 | 499 | def __init__(self, client: AsyncGroq) -> None:
|
406 |
| - self.chat = chat.AsyncChatWithRawResponse(client.chat) |
407 |
| - self.embeddings = embeddings.AsyncEmbeddingsWithRawResponse(client.embeddings) |
408 |
| - self.audio = audio.AsyncAudioWithRawResponse(client.audio) |
409 |
| - self.models = models.AsyncModelsWithRawResponse(client.models) |
410 |
| - self.batches = batches.AsyncBatchesWithRawResponse(client.batches) |
411 |
| - self.files = files.AsyncFilesWithRawResponse(client.files) |
| 500 | + self._client = client |
| 501 | + |
| 502 | + @cached_property |
| 503 | + def chat(self) -> chat.AsyncChatWithRawResponse: |
| 504 | + from .resources.chat import AsyncChatWithRawResponse |
| 505 | + |
| 506 | + return AsyncChatWithRawResponse(self._client.chat) |
| 507 | + |
| 508 | + @cached_property |
| 509 | + def embeddings(self) -> embeddings.AsyncEmbeddingsWithRawResponse: |
| 510 | + from .resources.embeddings import AsyncEmbeddingsWithRawResponse |
| 511 | + |
| 512 | + return AsyncEmbeddingsWithRawResponse(self._client.embeddings) |
| 513 | + |
| 514 | + @cached_property |
| 515 | + def audio(self) -> audio.AsyncAudioWithRawResponse: |
| 516 | + from .resources.audio import AsyncAudioWithRawResponse |
| 517 | + |
| 518 | + return AsyncAudioWithRawResponse(self._client.audio) |
| 519 | + |
| 520 | + @cached_property |
| 521 | + def models(self) -> models.AsyncModelsWithRawResponse: |
| 522 | + from .resources.models import AsyncModelsWithRawResponse |
| 523 | + |
| 524 | + return AsyncModelsWithRawResponse(self._client.models) |
| 525 | + |
| 526 | + @cached_property |
| 527 | + def batches(self) -> batches.AsyncBatchesWithRawResponse: |
| 528 | + from .resources.batches import AsyncBatchesWithRawResponse |
| 529 | + |
| 530 | + return AsyncBatchesWithRawResponse(self._client.batches) |
| 531 | + |
| 532 | + @cached_property |
| 533 | + def files(self) -> files.AsyncFilesWithRawResponse: |
| 534 | + from .resources.files import AsyncFilesWithRawResponse |
| 535 | + |
| 536 | + return AsyncFilesWithRawResponse(self._client.files) |
412 | 537 |
|
413 | 538 |
|
414 | 539 | class GroqWithStreamedResponse:
|
| 540 | + _client: Groq |
| 541 | + |
415 | 542 | def __init__(self, client: Groq) -> None:
|
416 |
| - self.chat = chat.ChatWithStreamingResponse(client.chat) |
417 |
| - self.embeddings = embeddings.EmbeddingsWithStreamingResponse(client.embeddings) |
418 |
| - self.audio = audio.AudioWithStreamingResponse(client.audio) |
419 |
| - self.models = models.ModelsWithStreamingResponse(client.models) |
420 |
| - self.batches = batches.BatchesWithStreamingResponse(client.batches) |
421 |
| - self.files = files.FilesWithStreamingResponse(client.files) |
| 543 | + self._client = client |
| 544 | + |
| 545 | + @cached_property |
| 546 | + def chat(self) -> chat.ChatWithStreamingResponse: |
| 547 | + from .resources.chat import ChatWithStreamingResponse |
| 548 | + |
| 549 | + return ChatWithStreamingResponse(self._client.chat) |
| 550 | + |
| 551 | + @cached_property |
| 552 | + def embeddings(self) -> embeddings.EmbeddingsWithStreamingResponse: |
| 553 | + from .resources.embeddings import EmbeddingsWithStreamingResponse |
| 554 | + |
| 555 | + return EmbeddingsWithStreamingResponse(self._client.embeddings) |
| 556 | + |
| 557 | + @cached_property |
| 558 | + def audio(self) -> audio.AudioWithStreamingResponse: |
| 559 | + from .resources.audio import AudioWithStreamingResponse |
| 560 | + |
| 561 | + return AudioWithStreamingResponse(self._client.audio) |
| 562 | + |
| 563 | + @cached_property |
| 564 | + def models(self) -> models.ModelsWithStreamingResponse: |
| 565 | + from .resources.models import ModelsWithStreamingResponse |
| 566 | + |
| 567 | + return ModelsWithStreamingResponse(self._client.models) |
| 568 | + |
| 569 | + @cached_property |
| 570 | + def batches(self) -> batches.BatchesWithStreamingResponse: |
| 571 | + from .resources.batches import BatchesWithStreamingResponse |
| 572 | + |
| 573 | + return BatchesWithStreamingResponse(self._client.batches) |
| 574 | + |
| 575 | + @cached_property |
| 576 | + def files(self) -> files.FilesWithStreamingResponse: |
| 577 | + from .resources.files import FilesWithStreamingResponse |
| 578 | + |
| 579 | + return FilesWithStreamingResponse(self._client.files) |
422 | 580 |
|
423 | 581 |
|
424 | 582 | class AsyncGroqWithStreamedResponse:
|
| 583 | + _client: AsyncGroq |
| 584 | + |
425 | 585 | def __init__(self, client: AsyncGroq) -> None:
|
426 |
| - self.chat = chat.AsyncChatWithStreamingResponse(client.chat) |
427 |
| - self.embeddings = embeddings.AsyncEmbeddingsWithStreamingResponse(client.embeddings) |
428 |
| - self.audio = audio.AsyncAudioWithStreamingResponse(client.audio) |
429 |
| - self.models = models.AsyncModelsWithStreamingResponse(client.models) |
430 |
| - self.batches = batches.AsyncBatchesWithStreamingResponse(client.batches) |
431 |
| - self.files = files.AsyncFilesWithStreamingResponse(client.files) |
| 586 | + self._client = client |
| 587 | + |
| 588 | + @cached_property |
| 589 | + def chat(self) -> chat.AsyncChatWithStreamingResponse: |
| 590 | + from .resources.chat import AsyncChatWithStreamingResponse |
| 591 | + |
| 592 | + return AsyncChatWithStreamingResponse(self._client.chat) |
| 593 | + |
| 594 | + @cached_property |
| 595 | + def embeddings(self) -> embeddings.AsyncEmbeddingsWithStreamingResponse: |
| 596 | + from .resources.embeddings import AsyncEmbeddingsWithStreamingResponse |
| 597 | + |
| 598 | + return AsyncEmbeddingsWithStreamingResponse(self._client.embeddings) |
| 599 | + |
| 600 | + @cached_property |
| 601 | + def audio(self) -> audio.AsyncAudioWithStreamingResponse: |
| 602 | + from .resources.audio import AsyncAudioWithStreamingResponse |
| 603 | + |
| 604 | + return AsyncAudioWithStreamingResponse(self._client.audio) |
| 605 | + |
| 606 | + @cached_property |
| 607 | + def models(self) -> models.AsyncModelsWithStreamingResponse: |
| 608 | + from .resources.models import AsyncModelsWithStreamingResponse |
| 609 | + |
| 610 | + return AsyncModelsWithStreamingResponse(self._client.models) |
| 611 | + |
| 612 | + @cached_property |
| 613 | + def batches(self) -> batches.AsyncBatchesWithStreamingResponse: |
| 614 | + from .resources.batches import AsyncBatchesWithStreamingResponse |
| 615 | + |
| 616 | + return AsyncBatchesWithStreamingResponse(self._client.batches) |
| 617 | + |
| 618 | + @cached_property |
| 619 | + def files(self) -> files.AsyncFilesWithStreamingResponse: |
| 620 | + from .resources.files import AsyncFilesWithStreamingResponse |
| 621 | + |
| 622 | + return AsyncFilesWithStreamingResponse(self._client.files) |
432 | 623 |
|
433 | 624 |
|
434 | 625 | Client = Groq
|
|
0 commit comments