diff --git a/langchain/callbacks/streaming_aiter.py b/langchain/callbacks/streaming_aiter.py index 47372dd9..cc66d9a4 100644 --- a/langchain/callbacks/streaming_aiter.py +++ b/langchain/callbacks/streaming_aiter.py @@ -58,7 +58,8 @@ class AsyncIteratorCallbackHandler(AsyncCallbackHandler): ) # Cancel the other task - other.pop().cancel() + if other: + other.pop().cancel() # Extract the value of the first completed task token_or_done = cast(Union[str, Literal[True]], done.pop().result())