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<Self>
pub fn whole(part: Part, content: &AssistantContent) -> Vec<Self>
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§impl Debug for StreamEvent
impl Debug for StreamEvent
Source§impl<'de> Deserialize<'de> for StreamEvent
impl<'de> Deserialize<'de> for StreamEvent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for StreamEvent
impl PartialEq for StreamEvent
Source§impl Serialize for StreamEvent
impl Serialize for StreamEvent
impl StructuralPartialEq for StreamEvent
Auto Trait Implementations§
impl Forget for StreamEvent
impl Freeze for StreamEvent
impl Move for StreamEvent
impl RefUnwindSafe for StreamEvent
impl Send for StreamEvent
impl Sync for StreamEvent
impl Unpin for StreamEvent
impl UnsafeUnpin for StreamEvent
impl UnwindSafe for StreamEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more