Skip to contents

stream_async() sends a module's prompt to the model and returns ellmer's async generator of text chunks, for use inside an asynchronous function (for example with the coro package). The response is plain streamed text: the signature's output types are not applied. For per-field callbacks and structured results, use run_stream().

Usage

stream_async(module, ..., .llm = NULL)

Arguments

module

A prediction module from module() or chain_of_thought(). Other modules are rejected before any request; use run() for them.

...

Inputs named after the signature's input fields.

.llm

An ellmer Chat; see run() for how it is chosen when omitted.

Value

An async generator that yields the response text in chunks.

Details

The generator comes from ellmer's Chat$stream_async(). The call does not use the response cache and records no trace.

Examples

if (FALSE) { # \dontrun{
storyteller <- module(signature("topic -> story"))
chunks <- stream_async(
  storyteller,
  topic = "a lighthouse keeper",
  .llm = ellmer::chat_openai(model = "gpt-6-luna")
)

print_chunks <- coro::async(function(generator) {
  for (chunk in coro::await_each(generator)) cat(chunk)
})
print_chunks(chunks)
} # }