pub enum StreamEvent {
MessageStart {
message_id: String,
},
TextDelta {
text: String,
},
ToolCallStart {
index: usize,
id: String,
name: String,
},
ToolCallDelta {
index: usize,
arguments_delta: String,
},
ToolCallEnd {
index: usize,
},
MessageEnd {
stop_reason: StopReason,
usage: Option<Usage>,
},
Error {
message: String,
code: Option<String>,
},
}Expand description
Events emitted by a completion stream
The stream produces a sequence of these events as the model generates its response. Consumers should handle each event type appropriately.
§Event Flow
A typical stream might look like:
MessageStart- Begin of responseTextDelta(multiple) - Text being generatedToolCallStart- Beginning of a tool callToolCallDelta- Tool call arguments streamingToolCallEnd- Tool call completeMessageEnd- Response finished
Or in error case:
MessageStartError- Something went wrong
Variants§
MessageStart
The message has started
TextDelta
A chunk of text content
ToolCallStart
A tool call is starting
Fields
ToolCallDelta
Arguments for a tool call (streamed)
ToolCallEnd
A tool call has completed
MessageEnd
The message has ended
Error
An error occurred during streaming
Implementations§
Source§impl StreamEvent
impl StreamEvent
Sourcepub fn text_delta(text: impl Into<String>) -> Self
pub fn text_delta(text: impl Into<String>) -> Self
Create a text delta event
Sourcepub fn message_start(message_id: impl Into<String>) -> Self
pub fn message_start(message_id: impl Into<String>) -> Self
Create a message start event
Sourcepub fn message_end(stop_reason: StopReason) -> Self
pub fn message_end(stop_reason: StopReason) -> Self
Create a message end event
Sourcepub fn is_text_delta(&self) -> bool
pub fn is_text_delta(&self) -> bool
Check if this is a text delta
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze 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
Mutably borrows from an owned value. Read more