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().
Arguments
- module
A prediction module from
module()orchain_of_thought(). Other modules are rejected before any request; userun()for them.- ...
Inputs named after the signature's input fields.
- .llm
An ellmer Chat; see
run()for how it is chosen when omitted.
Details
The generator comes from ellmer's Chat$stream_async(). The call does not
use the response cache and records no trace.
See also
Other execution:
concurrency_control(),
evaluate(),
predict.Module(),
run(),
run_async(),
run_dataset(),
run_stream(),
stream_listener()
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)
} # }