Skip to content

Commit 17b88d9

Browse files
chore(internal): add request options to SSE classes
1 parent fa4da88 commit 17b88d9

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/gradient/_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/gradient/_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 Gradient, AsyncGradient
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: Gradient,
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

@@ -104,7 +107,7 @@ class AsyncStream(Generic[_T]):
104107
"""Provides the core interface to iterate over an asynchronous stream response."""
105108

106109
response: httpx.Response
107-
110+
_options: Optional[FinalRequestOptions] = None
108111
_decoder: SSEDecoder | SSEBytesDecoder
109112

110113
def __init__(
@@ -113,10 +116,12 @@ def __init__(
113116
cast_to: type[_T],
114117
response: httpx.Response,
115118
client: AsyncGradient,
119+
options: Optional[FinalRequestOptions] = None,
116120
) -> None:
117121
self.response = response
118122
self._cast_to = cast_to
119123
self._client = client
124+
self._options = options
120125
self._decoder = client._make_sse_decoder()
121126
self._iterator = self.__stream__()
122127

0 commit comments

Comments
 (0)