Skip to content

Commit 0a06d6a

Browse files
committed
chore: revert binary streaming change (#875)
1 parent 2470d25 commit 0a06d6a

File tree

6 files changed

+9
-69
lines changed

6 files changed

+9
-69
lines changed

examples/audio.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
def main() -> None:
1414
# Create text-to-speech audio file
1515
response = openai.audio.speech.create(
16-
model="tts-1",
17-
voice="alloy",
18-
input="the quick brown fox jumped over the lazy dogs",
19-
stream=True,
16+
model="tts-1", voice="alloy", input="the quick brown fox jumped over the lazy dogs"
2017
)
2118

2219
response.stream_to_file(speech_file_path)

src/openai/_base_client.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ def _request(
863863
self._prepare_request(request)
864864

865865
try:
866-
response = self._client.send(request, auth=self.custom_auth, stream=stream or options.stream or False)
866+
response = self._client.send(request, auth=self.custom_auth, stream=stream)
867867
log.debug(
868868
'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
869869
)
@@ -1304,7 +1304,7 @@ async def _request(
13041304
await self._prepare_request(request)
13051305

13061306
try:
1307-
response = await self._client.send(request, auth=self.custom_auth, stream=stream or options.stream or False)
1307+
response = await self._client.send(request, auth=self.custom_auth, stream=stream)
13081308
log.debug(
13091309
'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
13101310
)
@@ -1541,7 +1541,6 @@ def make_request_options(
15411541
idempotency_key: str | None = None,
15421542
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
15431543
post_parser: PostParser | NotGiven = NOT_GIVEN,
1544-
stream: bool | None = None,
15451544
) -> RequestOptions:
15461545
"""Create a dict of type RequestOptions without keys of NotGiven values."""
15471546
options: RequestOptions = {}
@@ -1563,9 +1562,6 @@ def make_request_options(
15631562
if idempotency_key is not None:
15641563
options["idempotency_key"] = idempotency_key
15651564

1566-
if stream is not None:
1567-
options["stream"] = stream
1568-
15691565
if is_given(post_parser):
15701566
# internal
15711567
options["post_parser"] = post_parser # type: ignore

src/openai/_models.py

-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ class FinalRequestOptionsInput(TypedDict, total=False):
403403
params: Query
404404
headers: Headers
405405
max_retries: int
406-
stream: bool | None
407406
timeout: float | Timeout | None
408407
files: HttpxRequestFiles | None
409408
idempotency_key: str
@@ -421,7 +420,6 @@ class FinalRequestOptions(pydantic.BaseModel):
421420
timeout: Union[float, Timeout, None, NotGiven] = NotGiven()
422421
files: Union[HttpxRequestFiles, None] = None
423422
idempotency_key: Union[str, None] = None
424-
stream: Union[bool, None] = None
425423
post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven()
426424

427425
# It should be noted that we cannot use `json` here as that would override

src/openai/_types.py

+2-21
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,7 @@ def stream_to_file(
130130
chunk_size: int | None = None,
131131
) -> None:
132132
"""
133-
Stream the output to the given file. NOTE, requires passing `stream=True`
134-
to the request for expected behavior, e.g.,
135-
136-
response = openai.audio.speech.create(
137-
model="tts-1",
138-
voice="alloy",
139-
input="the quick brown fox jumped over the lazy dogs",
140-
stream=True,
141-
)
142-
response.stream_to_file(speech_file_path)
133+
Stream the output to the given file.
143134
"""
144135
pass
145136

@@ -194,16 +185,7 @@ async def astream_to_file(
194185
chunk_size: int | None = None,
195186
) -> None:
196187
"""
197-
Stream the output to the given file. NOTE, requires passing `stream=True`
198-
to the request for expected behavior, e.g.,
199-
200-
response = await openai.audio.speech.create(
201-
model="tts-1",
202-
voice="alloy",
203-
input="the quick brown fox jumped over the lazy dogs",
204-
stream=True,
205-
)
206-
response.stream_to_file(speech_file_path)
188+
Stream the output to the given file.
207189
"""
208190
pass
209191

@@ -275,7 +257,6 @@ async def aclose(self) -> None:
275257
class RequestOptions(TypedDict, total=False):
276258
headers: Headers
277259
max_retries: int
278-
stream: bool
279260
timeout: float | Timeout | None
280261
params: Query
281262
extra_json: AnyMapping

src/openai/resources/audio/speech.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def create(
4141
extra_query: Query | None = None,
4242
extra_body: Body | None = None,
4343
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
44-
stream: bool | None = None,
4544
) -> HttpxBinaryResponseContent:
4645
"""
4746
Generates audio from the input text.
@@ -68,9 +67,6 @@ def create(
6867
extra_body: Add additional JSON properties to the request
6968
7069
timeout: Override the client-level default timeout for this request, in seconds
71-
72-
stream: Whether or not the response content should be streamed (i.e. not read to
73-
completion immediately), default False
7470
"""
7571
return self._post(
7672
"/audio/speech",
@@ -85,11 +81,7 @@ def create(
8581
speech_create_params.SpeechCreateParams,
8682
),
8783
options=make_request_options(
88-
extra_headers=extra_headers,
89-
extra_query=extra_query,
90-
extra_body=extra_body,
91-
timeout=timeout,
92-
stream=stream,
84+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
9385
),
9486
cast_to=HttpxBinaryResponseContent,
9587
)
@@ -116,7 +108,6 @@ async def create(
116108
extra_query: Query | None = None,
117109
extra_body: Body | None = None,
118110
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
119-
stream: bool | None = None,
120111
) -> HttpxBinaryResponseContent:
121112
"""
122113
Generates audio from the input text.
@@ -143,9 +134,6 @@ async def create(
143134
extra_body: Add additional JSON properties to the request
144135
145136
timeout: Override the client-level default timeout for this request, in seconds
146-
147-
stream: Whether or not the response content should be streamed (i.e. not read to
148-
completion immediately), default False
149137
"""
150138
return await self._post(
151139
"/audio/speech",
@@ -160,11 +148,7 @@ async def create(
160148
speech_create_params.SpeechCreateParams,
161149
),
162150
options=make_request_options(
163-
extra_headers=extra_headers,
164-
extra_query=extra_query,
165-
extra_body=extra_body,
166-
timeout=timeout,
167-
stream=stream,
151+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
168152
),
169153
cast_to=HttpxBinaryResponseContent,
170154
)

src/openai/resources/files.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def content(
212212
extra_query: Query | None = None,
213213
extra_body: Body | None = None,
214214
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
215-
stream: bool | None = None,
216215
) -> HttpxBinaryResponseContent:
217216
"""
218217
Returns the contents of the specified file.
@@ -225,18 +224,11 @@ def content(
225224
extra_body: Add additional JSON properties to the request
226225
227226
timeout: Override the client-level default timeout for this request, in seconds
228-
229-
stream: Whether or not the response content should be streamed (i.e. not read to
230-
completion immediately), default False
231227
"""
232228
return self._get(
233229
f"/files/{file_id}/content",
234230
options=make_request_options(
235-
extra_headers=extra_headers,
236-
extra_query=extra_query,
237-
extra_body=extra_body,
238-
timeout=timeout,
239-
stream=stream,
231+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
240232
),
241233
cast_to=HttpxBinaryResponseContent,
242234
)
@@ -483,7 +475,6 @@ async def content(
483475
extra_query: Query | None = None,
484476
extra_body: Body | None = None,
485477
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
486-
stream: bool | None = None,
487478
) -> HttpxBinaryResponseContent:
488479
"""
489480
Returns the contents of the specified file.
@@ -496,18 +487,11 @@ async def content(
496487
extra_body: Add additional JSON properties to the request
497488
498489
timeout: Override the client-level default timeout for this request, in seconds
499-
500-
stream: Whether or not the response content should be streamed (i.e. not read to
501-
completion immediately), default False
502490
"""
503491
return await self._get(
504492
f"/files/{file_id}/content",
505493
options=make_request_options(
506-
extra_headers=extra_headers,
507-
extra_query=extra_query,
508-
extra_body=extra_body,
509-
timeout=timeout,
510-
stream=stream,
494+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
511495
),
512496
cast_to=HttpxBinaryResponseContent,
513497
)

0 commit comments

Comments
 (0)