nemoguardrails.streaming
Module Contents
Classes
Data
API
Bases: AsyncIterator
Provider-agnostic streaming handler with prefix/suffix/stop handling.
Implements AsyncIterator interface so it can be used directly to stream back the response. Chunks are pushed via push_chunk() and consumed via async iteration.
Process a chunk of text.
If we’re in buffering mode, record the text. Otherwise, update the full completion, check for stop tokens, and enqueue the chunk.
When we disable the buffer, we process the buffer as a chunk.
Signal end of stream.
Push a new string chunk to the stream.
Parameters:
String chunk to push, None to signal end of stream, or END_OF_STREAM sentinel.
Optional metadata about the generation.
Sets the pattern that is expected.
If a prefix or a suffix are specified, they will be removed from the output.
Waits until the stream finishes and returns the full completion.
Waits for top k non-empty lines from the LLM.
When k lines have been received (and k+1 has been started) it will return and remove them from the buffer.