File tree Expand file tree Collapse file tree
src/openai/lib/streaming/responses Expand file tree Collapse file tree Original file line number Diff line number Diff 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:
You can’t perform that action at this time.
0 commit comments