Commit 2d85e1e7

Stainless Bot <107565488+stainless-bot@users.noreply.github.com>
2023-11-24 06:34:15
chore: revert binary streaming change (#875)
1 parent 2fc3204
Changed files (6)
examples/audio.py
@@ -13,10 +13,7 @@ speech_file_path = Path(__file__).parent / "speech.mp3"
 def main() -> None:
     # Create text-to-speech audio file
     response = openai.audio.speech.create(
-        model="tts-1",
-        voice="alloy",
-        input="the quick brown fox jumped over the lazy dogs",
-        stream=True,
+        model="tts-1", voice="alloy", input="the quick brown fox jumped over the lazy dogs"
     )
 
     response.stream_to_file(speech_file_path)
src/openai/resources/audio/speech.py
@@ -41,7 +41,6 @@ class Speech(SyncAPIResource):
         extra_query: Query | None = None,
         extra_body: Body | None = None,
         timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
-        stream: bool | None = None,
     ) -> HttpxBinaryResponseContent:
         """
         Generates audio from the input text.
@@ -68,9 +67,6 @@ class Speech(SyncAPIResource):
           extra_body: Add additional JSON properties to the request
 
           timeout: Override the client-level default timeout for this request, in seconds
-
-          stream: Whether or not the response content should be streamed (i.e. not read to
-              completion immediately), default False
         """
         return self._post(
             "/audio/speech",
@@ -85,11 +81,7 @@ class Speech(SyncAPIResource):
                 speech_create_params.SpeechCreateParams,
             ),
             options=make_request_options(
-                extra_headers=extra_headers,
-                extra_query=extra_query,
-                extra_body=extra_body,
-                timeout=timeout,
-                stream=stream,
+                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
             ),
             cast_to=HttpxBinaryResponseContent,
         )
@@ -116,7 +108,6 @@ class AsyncSpeech(AsyncAPIResource):
         extra_query: Query | None = None,
         extra_body: Body | None = None,
         timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
-        stream: bool | None = None,
     ) -> HttpxBinaryResponseContent:
         """
         Generates audio from the input text.
@@ -143,9 +134,6 @@ class AsyncSpeech(AsyncAPIResource):
           extra_body: Add additional JSON properties to the request
 
           timeout: Override the client-level default timeout for this request, in seconds
-
-          stream: Whether or not the response content should be streamed (i.e. not read to
-              completion immediately), default False
         """
         return await self._post(
             "/audio/speech",
@@ -160,11 +148,7 @@ class AsyncSpeech(AsyncAPIResource):
                 speech_create_params.SpeechCreateParams,
             ),
             options=make_request_options(
-                extra_headers=extra_headers,
-                extra_query=extra_query,
-                extra_body=extra_body,
-                timeout=timeout,
-                stream=stream,
+                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
             ),
             cast_to=HttpxBinaryResponseContent,
         )
src/openai/resources/files.py
@@ -212,7 +212,6 @@ class Files(SyncAPIResource):
         extra_query: Query | None = None,
         extra_body: Body | None = None,
         timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
-        stream: bool | None = None,
     ) -> HttpxBinaryResponseContent:
         """
         Returns the contents of the specified file.
@@ -225,18 +224,11 @@ class Files(SyncAPIResource):
           extra_body: Add additional JSON properties to the request
 
           timeout: Override the client-level default timeout for this request, in seconds
-
-          stream: Whether or not the response content should be streamed (i.e. not read to
-              completion immediately), default False
         """
         return self._get(
             f"/files/{file_id}/content",
             options=make_request_options(
-                extra_headers=extra_headers,
-                extra_query=extra_query,
-                extra_body=extra_body,
-                timeout=timeout,
-                stream=stream,
+                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
             ),
             cast_to=HttpxBinaryResponseContent,
         )
@@ -483,7 +475,6 @@ class AsyncFiles(AsyncAPIResource):
         extra_query: Query | None = None,
         extra_body: Body | None = None,
         timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
-        stream: bool | None = None,
     ) -> HttpxBinaryResponseContent:
         """
         Returns the contents of the specified file.
@@ -496,18 +487,11 @@ class AsyncFiles(AsyncAPIResource):
           extra_body: Add additional JSON properties to the request
 
           timeout: Override the client-level default timeout for this request, in seconds
-
-          stream: Whether or not the response content should be streamed (i.e. not read to
-              completion immediately), default False
         """
         return await self._get(
             f"/files/{file_id}/content",
             options=make_request_options(
-                extra_headers=extra_headers,
-                extra_query=extra_query,
-                extra_body=extra_body,
-                timeout=timeout,
-                stream=stream,
+                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
             ),
             cast_to=HttpxBinaryResponseContent,
         )
src/openai/_base_client.py
@@ -863,7 +863,7 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
         self._prepare_request(request)
 
         try:
-            response = self._client.send(request, auth=self.custom_auth, stream=stream or options.stream or False)
+            response = self._client.send(request, auth=self.custom_auth, stream=stream)
             log.debug(
                 'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
             )
@@ -1304,7 +1304,7 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
         await self._prepare_request(request)
 
         try:
-            response = await self._client.send(request, auth=self.custom_auth, stream=stream or options.stream or False)
+            response = await self._client.send(request, auth=self.custom_auth, stream=stream)
             log.debug(
                 'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
             )
@@ -1541,7 +1541,6 @@ def make_request_options(
     idempotency_key: str | None = None,
     timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
     post_parser: PostParser | NotGiven = NOT_GIVEN,
-    stream: bool | None = None,
 ) -> RequestOptions:
     """Create a dict of type RequestOptions without keys of NotGiven values."""
     options: RequestOptions = {}
@@ -1563,9 +1562,6 @@ def make_request_options(
     if idempotency_key is not None:
         options["idempotency_key"] = idempotency_key
 
-    if stream is not None:
-        options["stream"] = stream
-
     if is_given(post_parser):
         # internal
         options["post_parser"] = post_parser  # type: ignore
src/openai/_models.py
@@ -403,7 +403,6 @@ class FinalRequestOptionsInput(TypedDict, total=False):
     params: Query
     headers: Headers
     max_retries: int
-    stream: bool | None
     timeout: float | Timeout | None
     files: HttpxRequestFiles | None
     idempotency_key: str
@@ -421,7 +420,6 @@ class FinalRequestOptions(pydantic.BaseModel):
     timeout: Union[float, Timeout, None, NotGiven] = NotGiven()
     files: Union[HttpxRequestFiles, None] = None
     idempotency_key: Union[str, None] = None
-    stream: Union[bool, None] = None
     post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven()
 
     # It should be noted that we cannot use `json` here as that would override
src/openai/_types.py
@@ -130,16 +130,7 @@ class BinaryResponseContent(ABC):
         chunk_size: int | None = None,
     ) -> None:
         """
-        Stream the output to the given file. NOTE, requires passing `stream=True`
-        to the request for expected behavior, e.g.,
-
-            response = openai.audio.speech.create(
-              model="tts-1",
-              voice="alloy",
-              input="the quick brown fox jumped over the lazy dogs",
-              stream=True,
-            )
-            response.stream_to_file(speech_file_path)
+        Stream the output to the given file.
         """
         pass
 
@@ -194,16 +185,7 @@ class BinaryResponseContent(ABC):
         chunk_size: int | None = None,
     ) -> None:
         """
-        Stream the output to the given file. NOTE, requires passing `stream=True`
-        to the request for expected behavior, e.g.,
-
-            response = await openai.audio.speech.create(
-              model="tts-1",
-              voice="alloy",
-              input="the quick brown fox jumped over the lazy dogs",
-              stream=True,
-            )
-            response.stream_to_file(speech_file_path)
+        Stream the output to the given file.
         """
         pass
 
@@ -275,7 +257,6 @@ else:
 class RequestOptions(TypedDict, total=False):
     headers: Headers
     max_retries: int
-    stream: bool
     timeout: float | Timeout | None
     params: Query
     extra_json: AnyMapping