File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,9 @@ def __stream__(self) -> Iterator[ResponseT]:
47
47
cast_to = self ._cast_to
48
48
response = self .response
49
49
process_data = self ._client ._process_response_data
50
+ iterator = self ._iter_events ()
50
51
51
- for sse in self . _iter_events () :
52
+ for sse in iterator :
52
53
if sse .data .startswith ("[DONE]" ):
53
54
break
54
55
@@ -63,6 +64,10 @@ def __stream__(self) -> Iterator[ResponseT]:
63
64
64
65
yield process_data (data = data , cast_to = cast_to , response = response )
65
66
67
+ # Ensure the entire stream is consumed
68
+ for sse in iterator :
69
+ ...
70
+
66
71
67
72
class AsyncStream (Generic [ResponseT ]):
68
73
"""Provides the core interface to iterate over an asynchronous stream response."""
@@ -97,8 +102,9 @@ async def __stream__(self) -> AsyncIterator[ResponseT]:
97
102
cast_to = self ._cast_to
98
103
response = self .response
99
104
process_data = self ._client ._process_response_data
105
+ iterator = self ._iter_events ()
100
106
101
- async for sse in self . _iter_events () :
107
+ async for sse in iterator :
102
108
if sse .data .startswith ("[DONE]" ):
103
109
break
104
110
@@ -113,6 +119,10 @@ async def __stream__(self) -> AsyncIterator[ResponseT]:
113
119
114
120
yield process_data (data = data , cast_to = cast_to , response = response )
115
121
122
+ # Ensure the entire stream is consumed
123
+ async for sse in iterator :
124
+ ...
125
+
116
126
117
127
class ServerSentEvent :
118
128
def __init__ (
You can’t perform that action at this time.
0 commit comments