pub enum StreamEvent {
Start {
part: Part,
kind: PartKind,
name: Option<ToolName>,
},
Text {
part: Part,
text: String,
},
Reasoning {
part: Part,
text: String,
},
Arguments {
part: Part,
json: String,
},
End {
part: Part,
content: AssistantContent,
},
}Expand description
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 StreamRecord::parse to check it.
Variants§
Start
A part opened. A tool call opens once its tool is named, so a call streams its arguments under a known tool.
Fields
name: Option<ToolName>The tool a PartKind::ToolCall names as it opens; None for
every other kind. The call’s end states the name it settled on.
Text
A text part grew.
Reasoning
A reasoning part grew.
Arguments
A tool call’s arguments grew. The fragments of one call, joined,
are the argument JSON the provider sent; read an incomplete prefix
with parse_partial_arguments.
End
A part ended with the content it finalized.
Implementations§
Source§impl StreamEvent
impl StreamEvent
Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
A stable variant name that exposes no payload to logs.
Sourcepub fn whole(part: Part, content: &AssistantContent) -> Vec<StreamEvent>
pub fn whole(part: Part, content: &AssistantContent) -> Vec<StreamEvent>
The events a stream writes for content arriving whole as the part
at part: its start, its text, reasoning or argument text as one
fragment, and its end holding content. Empty text writes no
fragment. A call’s fragment is its
raw_arguments: the
text the model sent when it was not an object, else the object.
use rig_core::message::AssistantContent;
use rig_core::streaming::{Part, StreamEvent};
let events = StreamEvent::whole(Part::new(0), &AssistantContent::text("Hi"));
let names: Vec<_> = events.iter().map(StreamEvent::name).collect();
assert_eq!(names, ["Start", "Text", "End"]);Trait Implementations§
Source§impl Clone for StreamEvent
impl Clone for StreamEvent
Source§fn clone(&self) -> StreamEvent
fn clone(&self) -> StreamEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more