Skip to content

Commit c612cfb

Browse files
chore(internal): add request options to SSE classes
1 parent 849c8df commit c612cfb

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/openai/_legacy_response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
221221
),
222222
response=self.http_response,
223223
client=cast(Any, self._client),
224+
options=self._options,
224225
),
225226
)
226227

@@ -231,6 +232,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
231232
cast_to=extract_stream_chunk_type(self._stream_cls),
232233
response=self.http_response,
233234
client=cast(Any, self._client),
235+
options=self._options,
234236
),
235237
)
236238

@@ -244,6 +246,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
244246
cast_to=cast_to,
245247
response=self.http_response,
246248
client=cast(Any, self._client),
249+
options=self._options,
247250
),
248251
)
249252

src/openai/_response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
152152
),
153153
response=self.http_response,
154154
client=cast(Any, self._client),
155+
options=self._options,
155156
),
156157
)
157158

@@ -162,6 +163,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
162163
cast_to=extract_stream_chunk_type(self._stream_cls),
163164
response=self.http_response,
164165
client=cast(Any, self._client),
166+
options=self._options,
165167
),
166168
)
167169

@@ -175,6 +177,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T:
175177
cast_to=cast_to,
176178
response=self.http_response,
177179
client=cast(Any, self._client),
180+
options=self._options,
178181
),
179182
)
180183

src/openai/_streaming.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import inspect
66
from types import TracebackType
7-
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, AsyncIterator, cast
7+
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, Optional, AsyncIterator, cast
88
from typing_extensions import Self, Protocol, TypeGuard, override, get_origin, runtime_checkable
99

1010
import httpx
@@ -14,6 +14,7 @@
1414

1515
if TYPE_CHECKING:
1616
from ._client import OpenAI, AsyncOpenAI
17+
from ._models import FinalRequestOptions
1718

1819

1920
_T = TypeVar("_T")
@@ -23,7 +24,7 @@ class Stream(Generic[_T]):
2324
"""Provides the core interface to iterate over a synchronous stream response."""
2425

2526
response: httpx.Response
26-
27+
_options: Optional[FinalRequestOptions] = None
2728
_decoder: SSEBytesDecoder
2829

2930
def __init__(
@@ -32,10 +33,12 @@ def __init__(
3233
cast_to: type[_T],
3334
response: httpx.Response,
3435
client: OpenAI,
36+
options: Optional[FinalRequestOptions] = None,
3537
) -> None:
3638
self.response = response
3739
self._cast_to = cast_to
3840
self._client = client
41+
self._options = options
3942
self._decoder = client._make_sse_decoder()
4043
self._iterator = self.__stream__()
4144

@@ -125,7 +128,7 @@ class AsyncStream(Generic[_T]):
125128
"""Provides the core interface to iterate over an asynchronous stream response."""
126129

127130
response: httpx.Response
128-
131+
_options: Optional[FinalRequestOptions] = None
129132
_decoder: SSEDecoder | SSEBytesDecoder
130133

131134
def __init__(
@@ -134,10 +137,12 @@ def __init__(
134137
cast_to: type[_T],
135138
response: httpx.Response,
136139
client: AsyncOpenAI,
140+
options: Optional[FinalRequestOptions] = None,
137141
) -> None:
138142
self.response = response
139143
self._cast_to = cast_to
140144
self._client = client
145+
self._options = options
141146
self._decoder = client._make_sse_decoder()
142147
self._iterator = self.__stream__()
143148

0 commit comments

Comments
 (0)