aiter() — langchain Function Reference
Architecture documentation for the aiter() function in streaming_aiter.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5a2284c4_e445_1a0c_e097_263832dc1143["aiter()"] 026a405e_b843_1fc9_0384_15895a6c1500["AsyncIteratorCallbackHandler"] 5a2284c4_e445_1a0c_e097_263832dc1143 -->|defined in| 026a405e_b843_1fc9_0384_15895a6c1500 style 5a2284c4_e445_1a0c_e097_263832dc1143 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/callbacks/streaming_aiter.py lines 56–83
async def aiter(self) -> AsyncIterator[str]:
"""Asynchronous iterator that yields tokens."""
while not self.queue.empty() or not self.done.is_set():
# Wait for the next token in the queue,
# but stop waiting if the done event is set
done, other = await asyncio.wait(
[
# NOTE: If you add other tasks here, update the code below,
# which assumes each set has exactly one task each
asyncio.ensure_future(self.queue.get()),
asyncio.ensure_future(self.done.wait()),
],
return_when=asyncio.FIRST_COMPLETED,
)
# Cancel the other task
if other:
other.pop().cancel()
# Extract the value of the first completed task
token_or_done = cast("str | Literal[True]", done.pop().result())
# If the extracted value is the boolean True, the done event was set
if token_or_done is True:
break
# Otherwise, the extracted value is a token, which we yield
yield token_or_done
Domain
Subdomains
Source
Frequently Asked Questions
What does aiter() do?
aiter() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/callbacks/streaming_aiter.py.
Where is aiter() defined?
aiter() is defined in libs/langchain/langchain_classic/callbacks/streaming_aiter.py at line 56.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free