Skip to content

Commit 111faaa

Browse files
author
giulio-leone
committed
fix: apply code review suggestions
Apply reviewer suggestions from PR review.
1 parent e977e56 commit 111faaa

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/openai/lib/streaming/responses/_responses.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ def cancel(self) -> Response:
113113
if response_id is None:
114114
raise ValueError("Cannot cancel: response ID not yet available. Wait for the first event.")
115115
if self._cancel_response is None:
116-
raise ValueError("Cancel not available for this stream.")
117-
self.close()
116+
try:
117+
result = self._cancel_response(response_id)
118+
finally:
119+
self.close()
118120
try:
119121
return self._cancel_response(response_id)
120122
except Exception:
@@ -242,8 +244,10 @@ async def cancel(self) -> Response:
242244
to cancel the response.
243245

244246
Returns the cancelled Response object.
245-
"""
246-
response_id = self.response_id
247+
try:
248+
result = await self._cancel_response(response_id)
249+
finally:
250+
await self.close()
247251
if response_id is None:
248252
raise ValueError("Cannot cancel: response ID not yet available. Wait for the first event.")
249253
if self._cancel_response is None:

0 commit comments

Comments
 (0)