Skip to content

Commit

Permalink
chore: lazy load raw resource class properties (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Jan 21, 2024
1 parent d5abe79 commit c484e0c
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 48 deletions.
64 changes: 52 additions & 12 deletions src/openai/resources/audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,67 @@ def with_streaming_response(self) -> AsyncAudioWithStreamingResponse:

class AudioWithRawResponse:
def __init__(self, audio: Audio) -> None:
self.transcriptions = TranscriptionsWithRawResponse(audio.transcriptions)
self.translations = TranslationsWithRawResponse(audio.translations)
self.speech = SpeechWithRawResponse(audio.speech)
self._audio = audio

@cached_property
def transcriptions(self) -> TranscriptionsWithRawResponse:
return TranscriptionsWithRawResponse(self._audio.transcriptions)

@cached_property
def translations(self) -> TranslationsWithRawResponse:
return TranslationsWithRawResponse(self._audio.translations)

@cached_property
def speech(self) -> SpeechWithRawResponse:
return SpeechWithRawResponse(self._audio.speech)


class AsyncAudioWithRawResponse:
def __init__(self, audio: AsyncAudio) -> None:
self.transcriptions = AsyncTranscriptionsWithRawResponse(audio.transcriptions)
self.translations = AsyncTranslationsWithRawResponse(audio.translations)
self.speech = AsyncSpeechWithRawResponse(audio.speech)
self._audio = audio

@cached_property
def transcriptions(self) -> AsyncTranscriptionsWithRawResponse:
return AsyncTranscriptionsWithRawResponse(self._audio.transcriptions)

@cached_property
def translations(self) -> AsyncTranslationsWithRawResponse:
return AsyncTranslationsWithRawResponse(self._audio.translations)

@cached_property
def speech(self) -> AsyncSpeechWithRawResponse:
return AsyncSpeechWithRawResponse(self._audio.speech)


class AudioWithStreamingResponse:
def __init__(self, audio: Audio) -> None:
self.transcriptions = TranscriptionsWithStreamingResponse(audio.transcriptions)
self.translations = TranslationsWithStreamingResponse(audio.translations)
self.speech = SpeechWithStreamingResponse(audio.speech)
self._audio = audio

@cached_property
def transcriptions(self) -> TranscriptionsWithStreamingResponse:
return TranscriptionsWithStreamingResponse(self._audio.transcriptions)

@cached_property
def translations(self) -> TranslationsWithStreamingResponse:
return TranslationsWithStreamingResponse(self._audio.translations)

@cached_property
def speech(self) -> SpeechWithStreamingResponse:
return SpeechWithStreamingResponse(self._audio.speech)


class AsyncAudioWithStreamingResponse:
def __init__(self, audio: AsyncAudio) -> None:
self.transcriptions = AsyncTranscriptionsWithStreamingResponse(audio.transcriptions)
self.translations = AsyncTranslationsWithStreamingResponse(audio.translations)
self.speech = AsyncSpeechWithStreamingResponse(audio.speech)
self._audio = audio

@cached_property
def transcriptions(self) -> AsyncTranscriptionsWithStreamingResponse:
return AsyncTranscriptionsWithStreamingResponse(self._audio.transcriptions)

@cached_property
def translations(self) -> AsyncTranslationsWithStreamingResponse:
return AsyncTranslationsWithStreamingResponse(self._audio.translations)

@cached_property
def speech(self) -> AsyncSpeechWithStreamingResponse:
return AsyncSpeechWithStreamingResponse(self._audio.speech)
8 changes: 8 additions & 0 deletions src/openai/resources/audio/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,26 @@ async def create(

class SpeechWithRawResponse:
def __init__(self, speech: Speech) -> None:
self._speech = speech

self.create = _legacy_response.to_raw_response_wrapper(
speech.create,
)


class AsyncSpeechWithRawResponse:
def __init__(self, speech: AsyncSpeech) -> None:
self._speech = speech

self.create = _legacy_response.async_to_raw_response_wrapper(
speech.create,
)


class SpeechWithStreamingResponse:
def __init__(self, speech: Speech) -> None:
self._speech = speech

self.create = to_custom_streamed_response_wrapper(
speech.create,
StreamedBinaryAPIResponse,
Expand All @@ -192,6 +198,8 @@ def __init__(self, speech: Speech) -> None:

class AsyncSpeechWithStreamingResponse:
def __init__(self, speech: AsyncSpeech) -> None:
self._speech = speech

self.create = async_to_custom_streamed_response_wrapper(
speech.create,
AsyncStreamedBinaryAPIResponse,
Expand Down
8 changes: 8 additions & 0 deletions src/openai/resources/audio/transcriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,35 @@ async def create(

class TranscriptionsWithRawResponse:
def __init__(self, transcriptions: Transcriptions) -> None:
self._transcriptions = transcriptions

self.create = _legacy_response.to_raw_response_wrapper(
transcriptions.create,
)


class AsyncTranscriptionsWithRawResponse:
def __init__(self, transcriptions: AsyncTranscriptions) -> None:
self._transcriptions = transcriptions

self.create = _legacy_response.async_to_raw_response_wrapper(
transcriptions.create,
)


class TranscriptionsWithStreamingResponse:
def __init__(self, transcriptions: Transcriptions) -> None:
self._transcriptions = transcriptions

self.create = to_streamed_response_wrapper(
transcriptions.create,
)


class AsyncTranscriptionsWithStreamingResponse:
def __init__(self, transcriptions: AsyncTranscriptions) -> None:
self._transcriptions = transcriptions

self.create = async_to_streamed_response_wrapper(
transcriptions.create,
)
8 changes: 8 additions & 0 deletions src/openai/resources/audio/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,35 @@ async def create(

class TranslationsWithRawResponse:
def __init__(self, translations: Translations) -> None:
self._translations = translations

self.create = _legacy_response.to_raw_response_wrapper(
translations.create,
)


class AsyncTranslationsWithRawResponse:
def __init__(self, translations: AsyncTranslations) -> None:
self._translations = translations

self.create = _legacy_response.async_to_raw_response_wrapper(
translations.create,
)


class TranslationsWithStreamingResponse:
def __init__(self, translations: Translations) -> None:
self._translations = translations

self.create = to_streamed_response_wrapper(
translations.create,
)


class AsyncTranslationsWithStreamingResponse:
def __init__(self, translations: AsyncTranslations) -> None:
self._translations = translations

self.create = async_to_streamed_response_wrapper(
translations.create,
)
24 changes: 20 additions & 4 deletions src/openai/resources/beta/assistants/assistants.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ async def delete(

class AssistantsWithRawResponse:
def __init__(self, assistants: Assistants) -> None:
self.files = FilesWithRawResponse(assistants.files)
self._assistants = assistants

self.create = _legacy_response.to_raw_response_wrapper(
assistants.create,
Expand All @@ -663,10 +663,14 @@ def __init__(self, assistants: Assistants) -> None:
assistants.delete,
)

@cached_property
def files(self) -> FilesWithRawResponse:
return FilesWithRawResponse(self._assistants.files)


class AsyncAssistantsWithRawResponse:
def __init__(self, assistants: AsyncAssistants) -> None:
self.files = AsyncFilesWithRawResponse(assistants.files)
self._assistants = assistants

self.create = _legacy_response.async_to_raw_response_wrapper(
assistants.create,
Expand All @@ -684,10 +688,14 @@ def __init__(self, assistants: AsyncAssistants) -> None:
assistants.delete,
)

@cached_property
def files(self) -> AsyncFilesWithRawResponse:
return AsyncFilesWithRawResponse(self._assistants.files)


class AssistantsWithStreamingResponse:
def __init__(self, assistants: Assistants) -> None:
self.files = FilesWithStreamingResponse(assistants.files)
self._assistants = assistants

self.create = to_streamed_response_wrapper(
assistants.create,
Expand All @@ -705,10 +713,14 @@ def __init__(self, assistants: Assistants) -> None:
assistants.delete,
)

@cached_property
def files(self) -> FilesWithStreamingResponse:
return FilesWithStreamingResponse(self._assistants.files)


class AsyncAssistantsWithStreamingResponse:
def __init__(self, assistants: AsyncAssistants) -> None:
self.files = AsyncFilesWithStreamingResponse(assistants.files)
self._assistants = assistants

self.create = async_to_streamed_response_wrapper(
assistants.create,
Expand All @@ -725,3 +737,7 @@ def __init__(self, assistants: AsyncAssistants) -> None:
self.delete = async_to_streamed_response_wrapper(
assistants.delete,
)

@cached_property
def files(self) -> AsyncFilesWithStreamingResponse:
return AsyncFilesWithStreamingResponse(self._assistants.files)
8 changes: 8 additions & 0 deletions src/openai/resources/beta/assistants/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ async def delete(

class FilesWithRawResponse:
def __init__(self, files: Files) -> None:
self._files = files

self.create = _legacy_response.to_raw_response_wrapper(
files.create,
)
Expand All @@ -426,6 +428,8 @@ def __init__(self, files: Files) -> None:

class AsyncFilesWithRawResponse:
def __init__(self, files: AsyncFiles) -> None:
self._files = files

self.create = _legacy_response.async_to_raw_response_wrapper(
files.create,
)
Expand All @@ -442,6 +446,8 @@ def __init__(self, files: AsyncFiles) -> None:

class FilesWithStreamingResponse:
def __init__(self, files: Files) -> None:
self._files = files

self.create = to_streamed_response_wrapper(
files.create,
)
Expand All @@ -458,6 +464,8 @@ def __init__(self, files: Files) -> None:

class AsyncFilesWithStreamingResponse:
def __init__(self, files: AsyncFiles) -> None:
self._files = files

self.create = async_to_streamed_response_wrapper(
files.create,
)
Expand Down
44 changes: 36 additions & 8 deletions src/openai/resources/beta/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,51 @@ def with_streaming_response(self) -> AsyncBetaWithStreamingResponse:

class BetaWithRawResponse:
def __init__(self, beta: Beta) -> None:
self.assistants = AssistantsWithRawResponse(beta.assistants)
self.threads = ThreadsWithRawResponse(beta.threads)
self._beta = beta

@cached_property
def assistants(self) -> AssistantsWithRawResponse:
return AssistantsWithRawResponse(self._beta.assistants)

@cached_property
def threads(self) -> ThreadsWithRawResponse:
return ThreadsWithRawResponse(self._beta.threads)


class AsyncBetaWithRawResponse:
def __init__(self, beta: AsyncBeta) -> None:
self.assistants = AsyncAssistantsWithRawResponse(beta.assistants)
self.threads = AsyncThreadsWithRawResponse(beta.threads)
self._beta = beta

@cached_property
def assistants(self) -> AsyncAssistantsWithRawResponse:
return AsyncAssistantsWithRawResponse(self._beta.assistants)

@cached_property
def threads(self) -> AsyncThreadsWithRawResponse:
return AsyncThreadsWithRawResponse(self._beta.threads)


class BetaWithStreamingResponse:
def __init__(self, beta: Beta) -> None:
self.assistants = AssistantsWithStreamingResponse(beta.assistants)
self.threads = ThreadsWithStreamingResponse(beta.threads)
self._beta = beta

@cached_property
def assistants(self) -> AssistantsWithStreamingResponse:
return AssistantsWithStreamingResponse(self._beta.assistants)

@cached_property
def threads(self) -> ThreadsWithStreamingResponse:
return ThreadsWithStreamingResponse(self._beta.threads)


class AsyncBetaWithStreamingResponse:
def __init__(self, beta: AsyncBeta) -> None:
self.assistants = AsyncAssistantsWithStreamingResponse(beta.assistants)
self.threads = AsyncThreadsWithStreamingResponse(beta.threads)
self._beta = beta

@cached_property
def assistants(self) -> AsyncAssistantsWithStreamingResponse:
return AsyncAssistantsWithStreamingResponse(self._beta.assistants)

@cached_property
def threads(self) -> AsyncThreadsWithStreamingResponse:
return AsyncThreadsWithStreamingResponse(self._beta.threads)
8 changes: 8 additions & 0 deletions src/openai/resources/beta/threads/messages/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def list(

class FilesWithRawResponse:
def __init__(self, files: Files) -> None:
self._files = files

self.retrieve = _legacy_response.to_raw_response_wrapper(
files.retrieve,
)
Expand All @@ -276,6 +278,8 @@ def __init__(self, files: Files) -> None:

class AsyncFilesWithRawResponse:
def __init__(self, files: AsyncFiles) -> None:
self._files = files

self.retrieve = _legacy_response.async_to_raw_response_wrapper(
files.retrieve,
)
Expand All @@ -286,6 +290,8 @@ def __init__(self, files: AsyncFiles) -> None:

class FilesWithStreamingResponse:
def __init__(self, files: Files) -> None:
self._files = files

self.retrieve = to_streamed_response_wrapper(
files.retrieve,
)
Expand All @@ -296,6 +302,8 @@ def __init__(self, files: Files) -> None:

class AsyncFilesWithStreamingResponse:
def __init__(self, files: AsyncFiles) -> None:
self._files = files

self.retrieve = async_to_streamed_response_wrapper(
files.retrieve,
)
Expand Down
Loading

0 comments on commit c484e0c

Please sign in to comment.