From 4661f303023624ed82bd0a0b3bff8bb2115f368a Mon Sep 17 00:00:00 2001 From: Deirdre Meehan Date: Fri, 28 Nov 2025 11:09:50 +0000 Subject: [PATCH] fix: consume stream --- src/groq/_streaming.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/groq/_streaming.py b/src/groq/_streaming.py index 69142627..3d4e27af 100644 --- a/src/groq/_streaming.py +++ b/src/groq/_streaming.py @@ -95,9 +95,9 @@ def __stream__(self) -> Iterator[_T]: ) yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response) - - # As we might not fully consume the response stream, we need to close it explicitly - response.close() + # The stream needs to be fully consumed to close the response + for _sse in iterator: + ... def __enter__(self) -> Self: return self @@ -196,9 +196,9 @@ async def __stream__(self) -> AsyncIterator[_T]: ) yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response) - - # As we might not fully consume the response stream, we need to close it explicitly - await response.aclose() + # The stream needs to be fully consumed to close the response + async for _sse in iterator: + ... async def __aenter__(self) -> Self: return self