what other types can be in this construct async f...
# ask-ai
r
what other types can be in this construct async for chunk in self._llm.chat(chat_ctx=chat_ctx): if isinstance(chunk, llm.ChatChunk): if chunk. i..e how do I generate text from llm literally?
t
Thanks for reaching out, Trevor. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're iterating a streaming LLM response and want to know what chunk types you can get and how to extract literal text. I’m responding about the async loop and extracting text from
llm.ChatChunk
. Quick answer: • The most common yielded type is
llm.ChatChunk
. It can include: ◦ text deltas (partial/streamed text) — available at
chunk.delta.content
◦ tool calls (instructions to call an external tool) ◦ metadata (usage, reasoning, events) • You may also see raw strings or
None
in some implementations. To safely get the generated text, check for
ChatChunk
and
delta.content
, and fall back to stringifying other chunk types. Example pattern:
Copy code
async for chunk in self._llm.chat(chat_ctx=chat_ctx):
    if isinstance(chunk, llm.ChatChunk) and hasattr(chunk.delta, "content"):
        text = chunk.delta.content
    else:
        text = str(chunk) if chunk is not None else None

    if text:
        # handle the text (print, yield, append, etc.)
        print(text, end="")
If you want, tell me: • which llm client/library/version you’re using, and • whether you need full responses assembled or incremental streaming output — I’ll give a tailored snippet. Sources: Modifying LLM output before TTS | LiveKit docs | Pipeline nodes and hooks | LiveKit docs