Expand description
Completion events, and Streamed, the one stream every reply arrives
as.
use rig_core::streaming::{Item, StreamEvent};
fn text(item: &Item<StreamEvent>) -> Option<&str> {
match item {
Item::Event(StreamEvent::Text { text, .. }) => Some(text),
_ => None,
}
}Structs§
- Part
- A part’s position in the response’s
choice. Only this crate constructs one, though it reads back from its serialized form: - Streamed
- One reply as it arrives: its events, and the fold that has seen each of
them. It is what
Model::streamreturns for every operation, and what a call finishes. - Transcript
- A completion stream’s items read back from their serialized form, in an order the writer could have produced: each part starts once, at a position no part took before, grows only while open and with its own kind of fragment, and ends once. Positions follow the order provider items opened, so a dropped item leaves a gap. Unmodeled payloads may come anywhere.
- Unknown
Payload - Unmodeled JSON payload with content-redacted
Debugoutput. Serialization preserves the payload;Self::valueexplicitly exposes it.
Enums§
- Item
- One item of a stream: an event of the operation, or a payload the provider sent that the decoder does not model. An unmodeled payload always reaches the consumer.
- Part
Kind - What kind of part a
StreamEvent::Startopened. - Relayed
- One item of a completion stream relayed over the bus: who the reply is from, an item of the reply, or the response the origin folded when the provider ended it.
- Sequence
Error - Why a serialized event sequence is not one the writer could produce.
- Stream
Event - One event of a completion stream: a part starts, grows, or ends with the
content it finalized. Deserializing one event checks nothing about its
order; read a sequence through
Transcript::parseto check it.
Functions§
- delivered
- The assistant content a stream’s
itemsdelivered, as its partial reply holds it: every part that ended, in start order, and the text of a text or reasoning part still open. The items hold no provider end, so no block keeps its provider item and the content replays canonically. - parse_
partial_ arguments - The best object a tool call’s argument text states so far, for showing a
call while it streams. It never fails: complete JSON parses as is, text
with raw control characters or invalid escapes is repaired first, a
cut-off prefix keeps the longest object it states
([
parse_partial_object]), and anything else is an empty object, as is a top level that is not an object.
Type Aliases§
- Completion
Stream - A streamed completion.
- Stream
Events - A completion stream as the bus carries it.