Skip to content

Commit d307127

Browse files
chore: lazy load raw resource class properties (#1087)
1 parent 36a7576 commit d307127

22 files changed

+336
-48
lines changed

src/openai/resources/audio/audio.py

+52-12
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,67 @@ def with_streaming_response(self) -> AsyncAudioWithStreamingResponse:
7878

7979
class AudioWithRawResponse:
8080
def __init__(self, audio: Audio) -> None:
81-
self.transcriptions = TranscriptionsWithRawResponse(audio.transcriptions)
82-
self.translations = TranslationsWithRawResponse(audio.translations)
83-
self.speech = SpeechWithRawResponse(audio.speech)
81+
self._audio = audio
82+
83+
@cached_property
84+
def transcriptions(self) -> TranscriptionsWithRawResponse:
85+
return TranscriptionsWithRawResponse(self._audio.transcriptions)
86+
87+
@cached_property
88+
def translations(self) -> TranslationsWithRawResponse:
89+
return TranslationsWithRawResponse(self._audio.translations)
90+
91+
@cached_property
92+
def speech(self) -> SpeechWithRawResponse:
93+
return SpeechWithRawResponse(self._audio.speech)
8494

8595

8696
class AsyncAudioWithRawResponse:
8797
def __init__(self, audio: AsyncAudio) -> None:
88-
self.transcriptions = AsyncTranscriptionsWithRawResponse(audio.transcriptions)
89-
self.translations = AsyncTranslationsWithRawResponse(audio.translations)
90-
self.speech = AsyncSpeechWithRawResponse(audio.speech)
98+
self._audio = audio
99+
100+
@cached_property
101+
def transcriptions(self) -> AsyncTranscriptionsWithRawResponse:
102+
return AsyncTranscriptionsWithRawResponse(self._audio.transcriptions)
103+
104+
@cached_property
105+
def translations(self) -> AsyncTranslationsWithRawResponse:
106+
return AsyncTranslationsWithRawResponse(self._audio.translations)
107+
108+
@cached_property
109+
def speech(self) -> AsyncSpeechWithRawResponse:
110+
return AsyncSpeechWithRawResponse(self._audio.speech)
91111

92112

93113
class AudioWithStreamingResponse:
94114
def __init__(self, audio: Audio) -> None:
95-
self.transcriptions = TranscriptionsWithStreamingResponse(audio.transcriptions)
96-
self.translations = TranslationsWithStreamingResponse(audio.translations)
97-
self.speech = SpeechWithStreamingResponse(audio.speech)
115+
self._audio = audio
116+
117+
@cached_property
118+
def transcriptions(self) -> TranscriptionsWithStreamingResponse:
119+
return TranscriptionsWithStreamingResponse(self._audio.transcriptions)
120+
121+
@cached_property
122+
def translations(self) -> TranslationsWithStreamingResponse:
123+
return TranslationsWithStreamingResponse(self._audio.translations)
124+
125+
@cached_property
126+
def speech(self) -> SpeechWithStreamingResponse:
127+
return SpeechWithStreamingResponse(self._audio.speech)
98128

99129

100130
class AsyncAudioWithStreamingResponse:
101131
def __init__(self, audio: AsyncAudio) -> None:
102-
self.transcriptions = AsyncTranscriptionsWithStreamingResponse(audio.transcriptions)
103-
self.translations = AsyncTranslationsWithStreamingResponse(audio.translations)
104-
self.speech = AsyncSpeechWithStreamingResponse(audio.speech)
132+
self._audio = audio
133+
134+
@cached_property
135+
def transcriptions(self) -> AsyncTranscriptionsWithStreamingResponse:
136+
return AsyncTranscriptionsWithStreamingResponse(self._audio.transcriptions)
137+
138+
@cached_property
139+
def translations(self) -> AsyncTranslationsWithStreamingResponse:
140+
return AsyncTranslationsWithStreamingResponse(self._audio.translations)
141+
142+
@cached_property
143+
def speech(self) -> AsyncSpeechWithStreamingResponse:
144+
return AsyncSpeechWithStreamingResponse(self._audio.speech)

src/openai/resources/audio/speech.py

+8
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,26 @@ async def create(
170170

171171
class SpeechWithRawResponse:
172172
def __init__(self, speech: Speech) -> None:
173+
self._speech = speech
174+
173175
self.create = _legacy_response.to_raw_response_wrapper(
174176
speech.create,
175177
)
176178

177179

178180
class AsyncSpeechWithRawResponse:
179181
def __init__(self, speech: AsyncSpeech) -> None:
182+
self._speech = speech
183+
180184
self.create = _legacy_response.async_to_raw_response_wrapper(
181185
speech.create,
182186
)
183187

184188

185189
class SpeechWithStreamingResponse:
186190
def __init__(self, speech: Speech) -> None:
191+
self._speech = speech
192+
187193
self.create = to_custom_streamed_response_wrapper(
188194
speech.create,
189195
StreamedBinaryAPIResponse,
@@ -192,6 +198,8 @@ def __init__(self, speech: Speech) -> None:
192198

193199
class AsyncSpeechWithStreamingResponse:
194200
def __init__(self, speech: AsyncSpeech) -> None:
201+
self._speech = speech
202+
195203
self.create = async_to_custom_streamed_response_wrapper(
196204
speech.create,
197205
AsyncStreamedBinaryAPIResponse,

src/openai/resources/audio/transcriptions.py

+8
Original file line numberDiff line numberDiff line change
@@ -199,27 +199,35 @@ async def create(
199199

200200
class TranscriptionsWithRawResponse:
201201
def __init__(self, transcriptions: Transcriptions) -> None:
202+
self._transcriptions = transcriptions
203+
202204
self.create = _legacy_response.to_raw_response_wrapper(
203205
transcriptions.create,
204206
)
205207

206208

207209
class AsyncTranscriptionsWithRawResponse:
208210
def __init__(self, transcriptions: AsyncTranscriptions) -> None:
211+
self._transcriptions = transcriptions
212+
209213
self.create = _legacy_response.async_to_raw_response_wrapper(
210214
transcriptions.create,
211215
)
212216

213217

214218
class TranscriptionsWithStreamingResponse:
215219
def __init__(self, transcriptions: Transcriptions) -> None:
220+
self._transcriptions = transcriptions
221+
216222
self.create = to_streamed_response_wrapper(
217223
transcriptions.create,
218224
)
219225

220226

221227
class AsyncTranscriptionsWithStreamingResponse:
222228
def __init__(self, transcriptions: AsyncTranscriptions) -> None:
229+
self._transcriptions = transcriptions
230+
223231
self.create = async_to_streamed_response_wrapper(
224232
transcriptions.create,
225233
)

src/openai/resources/audio/translations.py

+8
Original file line numberDiff line numberDiff line change
@@ -185,27 +185,35 @@ async def create(
185185

186186
class TranslationsWithRawResponse:
187187
def __init__(self, translations: Translations) -> None:
188+
self._translations = translations
189+
188190
self.create = _legacy_response.to_raw_response_wrapper(
189191
translations.create,
190192
)
191193

192194

193195
class AsyncTranslationsWithRawResponse:
194196
def __init__(self, translations: AsyncTranslations) -> None:
197+
self._translations = translations
198+
195199
self.create = _legacy_response.async_to_raw_response_wrapper(
196200
translations.create,
197201
)
198202

199203

200204
class TranslationsWithStreamingResponse:
201205
def __init__(self, translations: Translations) -> None:
206+
self._translations = translations
207+
202208
self.create = to_streamed_response_wrapper(
203209
translations.create,
204210
)
205211

206212

207213
class AsyncTranslationsWithStreamingResponse:
208214
def __init__(self, translations: AsyncTranslations) -> None:
215+
self._translations = translations
216+
209217
self.create = async_to_streamed_response_wrapper(
210218
translations.create,
211219
)

src/openai/resources/beta/assistants/assistants.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ async def delete(
645645

646646
class AssistantsWithRawResponse:
647647
def __init__(self, assistants: Assistants) -> None:
648-
self.files = FilesWithRawResponse(assistants.files)
648+
self._assistants = assistants
649649

650650
self.create = _legacy_response.to_raw_response_wrapper(
651651
assistants.create,
@@ -663,10 +663,14 @@ def __init__(self, assistants: Assistants) -> None:
663663
assistants.delete,
664664
)
665665

666+
@cached_property
667+
def files(self) -> FilesWithRawResponse:
668+
return FilesWithRawResponse(self._assistants.files)
669+
666670

667671
class AsyncAssistantsWithRawResponse:
668672
def __init__(self, assistants: AsyncAssistants) -> None:
669-
self.files = AsyncFilesWithRawResponse(assistants.files)
673+
self._assistants = assistants
670674

671675
self.create = _legacy_response.async_to_raw_response_wrapper(
672676
assistants.create,
@@ -684,10 +688,14 @@ def __init__(self, assistants: AsyncAssistants) -> None:
684688
assistants.delete,
685689
)
686690

691+
@cached_property
692+
def files(self) -> AsyncFilesWithRawResponse:
693+
return AsyncFilesWithRawResponse(self._assistants.files)
694+
687695

688696
class AssistantsWithStreamingResponse:
689697
def __init__(self, assistants: Assistants) -> None:
690-
self.files = FilesWithStreamingResponse(assistants.files)
698+
self._assistants = assistants
691699

692700
self.create = to_streamed_response_wrapper(
693701
assistants.create,
@@ -705,10 +713,14 @@ def __init__(self, assistants: Assistants) -> None:
705713
assistants.delete,
706714
)
707715

716+
@cached_property
717+
def files(self) -> FilesWithStreamingResponse:
718+
return FilesWithStreamingResponse(self._assistants.files)
719+
708720

709721
class AsyncAssistantsWithStreamingResponse:
710722
def __init__(self, assistants: AsyncAssistants) -> None:
711-
self.files = AsyncFilesWithStreamingResponse(assistants.files)
723+
self._assistants = assistants
712724

713725
self.create = async_to_streamed_response_wrapper(
714726
assistants.create,
@@ -725,3 +737,7 @@ def __init__(self, assistants: AsyncAssistants) -> None:
725737
self.delete = async_to_streamed_response_wrapper(
726738
assistants.delete,
727739
)
740+
741+
@cached_property
742+
def files(self) -> AsyncFilesWithStreamingResponse:
743+
return AsyncFilesWithStreamingResponse(self._assistants.files)

src/openai/resources/beta/assistants/files.py

+8
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ async def delete(
410410

411411
class FilesWithRawResponse:
412412
def __init__(self, files: Files) -> None:
413+
self._files = files
414+
413415
self.create = _legacy_response.to_raw_response_wrapper(
414416
files.create,
415417
)
@@ -426,6 +428,8 @@ def __init__(self, files: Files) -> None:
426428

427429
class AsyncFilesWithRawResponse:
428430
def __init__(self, files: AsyncFiles) -> None:
431+
self._files = files
432+
429433
self.create = _legacy_response.async_to_raw_response_wrapper(
430434
files.create,
431435
)
@@ -442,6 +446,8 @@ def __init__(self, files: AsyncFiles) -> None:
442446

443447
class FilesWithStreamingResponse:
444448
def __init__(self, files: Files) -> None:
449+
self._files = files
450+
445451
self.create = to_streamed_response_wrapper(
446452
files.create,
447453
)
@@ -458,6 +464,8 @@ def __init__(self, files: Files) -> None:
458464

459465
class AsyncFilesWithStreamingResponse:
460466
def __init__(self, files: AsyncFiles) -> None:
467+
self._files = files
468+
461469
self.create = async_to_streamed_response_wrapper(
462470
files.create,
463471
)

src/openai/resources/beta/beta.py

+36-8
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,51 @@ def with_streaming_response(self) -> AsyncBetaWithStreamingResponse:
6464

6565
class BetaWithRawResponse:
6666
def __init__(self, beta: Beta) -> None:
67-
self.assistants = AssistantsWithRawResponse(beta.assistants)
68-
self.threads = ThreadsWithRawResponse(beta.threads)
67+
self._beta = beta
68+
69+
@cached_property
70+
def assistants(self) -> AssistantsWithRawResponse:
71+
return AssistantsWithRawResponse(self._beta.assistants)
72+
73+
@cached_property
74+
def threads(self) -> ThreadsWithRawResponse:
75+
return ThreadsWithRawResponse(self._beta.threads)
6976

7077

7178
class AsyncBetaWithRawResponse:
7279
def __init__(self, beta: AsyncBeta) -> None:
73-
self.assistants = AsyncAssistantsWithRawResponse(beta.assistants)
74-
self.threads = AsyncThreadsWithRawResponse(beta.threads)
80+
self._beta = beta
81+
82+
@cached_property
83+
def assistants(self) -> AsyncAssistantsWithRawResponse:
84+
return AsyncAssistantsWithRawResponse(self._beta.assistants)
85+
86+
@cached_property
87+
def threads(self) -> AsyncThreadsWithRawResponse:
88+
return AsyncThreadsWithRawResponse(self._beta.threads)
7589

7690

7791
class BetaWithStreamingResponse:
7892
def __init__(self, beta: Beta) -> None:
79-
self.assistants = AssistantsWithStreamingResponse(beta.assistants)
80-
self.threads = ThreadsWithStreamingResponse(beta.threads)
93+
self._beta = beta
94+
95+
@cached_property
96+
def assistants(self) -> AssistantsWithStreamingResponse:
97+
return AssistantsWithStreamingResponse(self._beta.assistants)
98+
99+
@cached_property
100+
def threads(self) -> ThreadsWithStreamingResponse:
101+
return ThreadsWithStreamingResponse(self._beta.threads)
81102

82103

83104
class AsyncBetaWithStreamingResponse:
84105
def __init__(self, beta: AsyncBeta) -> None:
85-
self.assistants = AsyncAssistantsWithStreamingResponse(beta.assistants)
86-
self.threads = AsyncThreadsWithStreamingResponse(beta.threads)
106+
self._beta = beta
107+
108+
@cached_property
109+
def assistants(self) -> AsyncAssistantsWithStreamingResponse:
110+
return AsyncAssistantsWithStreamingResponse(self._beta.assistants)
111+
112+
@cached_property
113+
def threads(self) -> AsyncThreadsWithStreamingResponse:
114+
return AsyncThreadsWithStreamingResponse(self._beta.threads)

src/openai/resources/beta/threads/messages/files.py

+8
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ def list(
266266

267267
class FilesWithRawResponse:
268268
def __init__(self, files: Files) -> None:
269+
self._files = files
270+
269271
self.retrieve = _legacy_response.to_raw_response_wrapper(
270272
files.retrieve,
271273
)
@@ -276,6 +278,8 @@ def __init__(self, files: Files) -> None:
276278

277279
class AsyncFilesWithRawResponse:
278280
def __init__(self, files: AsyncFiles) -> None:
281+
self._files = files
282+
279283
self.retrieve = _legacy_response.async_to_raw_response_wrapper(
280284
files.retrieve,
281285
)
@@ -286,6 +290,8 @@ def __init__(self, files: AsyncFiles) -> None:
286290

287291
class FilesWithStreamingResponse:
288292
def __init__(self, files: Files) -> None:
293+
self._files = files
294+
289295
self.retrieve = to_streamed_response_wrapper(
290296
files.retrieve,
291297
)
@@ -296,6 +302,8 @@ def __init__(self, files: Files) -> None:
296302

297303
class AsyncFilesWithStreamingResponse:
298304
def __init__(self, files: AsyncFiles) -> None:
305+
self._files = files
306+
299307
self.retrieve = async_to_streamed_response_wrapper(
300308
files.retrieve,
301309
)

0 commit comments

Comments
 (0)