Commit 6132922c
Changed files (1)
src
openai
src/openai/_streaming.py
@@ -96,9 +96,8 @@ class Stream(Generic[_T]):
yield process_data(data=data, cast_to=cast_to, response=response)
- # Ensure the entire stream is consumed
- for _sse in iterator:
- ...
+ # As we might not fully consume the response stream, we need to close it explicitly
+ response.close()
def __enter__(self) -> Self:
return self
@@ -198,9 +197,8 @@ class AsyncStream(Generic[_T]):
yield process_data(data=data, cast_to=cast_to, response=response)
- # Ensure the entire stream is consumed
- async for _sse in iterator:
- ...
+ # As we might not fully consume the response stream, we need to close it explicitly
+ await response.aclose()
async def __aenter__(self) -> Self:
return self