Skip to main content

StreamPart

Enum StreamPart 

Source
#[non_exhaustive]
pub enum StreamPart {
Show 21 variants StreamStart { warnings: Vec<Warning>, }, ResponseMetadata { id: Option<String>, timestamp: Option<DateTime<Utc>>, model_id: Option<ModelId>, }, TextStart { id: PartId, provider_metadata: Option<ProviderMetadata>, }, TextDelta { id: PartId, delta: String, provider_metadata: Option<ProviderMetadata>, }, TextEnd { id: PartId, provider_metadata: Option<ProviderMetadata>, }, ReasoningStart { id: PartId, provider_metadata: Option<ProviderMetadata>, }, ReasoningDelta { id: PartId, delta: String, provider_metadata: Option<ProviderMetadata>, }, ReasoningEnd { id: PartId, provider_metadata: Option<ProviderMetadata>, }, ToolInputStart { id: ToolCallId, tool_name: ToolName, provider_executed: bool, dynamic: bool, title: Option<String>, provider_metadata: Option<ProviderMetadata>, }, ToolInputDelta { id: ToolCallId, delta: String, provider_metadata: Option<ProviderMetadata>, }, ToolInputEnd { id: ToolCallId, provider_metadata: Option<ProviderMetadata>, }, ToolCall(ToolCall), ToolResult(ProviderToolResult), ToolApprovalRequest { approval_id: ApprovalId, tool_call_id: ToolCallId, provider_metadata: Option<ProviderMetadata>, }, File { data: FileData, media_type: MediaType, filename: Option<String>, provider_metadata: Option<ProviderMetadata>, }, ReasoningFile { data: FileData, media_type: MediaType, provider_metadata: Option<ProviderMetadata>, }, Source(Source), Custom { kind: CustomKind, provider_metadata: Option<ProviderMetadata>, }, Finish { finish_reason: FinishReason, usage: Usage, provider_metadata: Option<ProviderMetadata>, }, Raw { raw_value: JsonValue, }, Error { error: StreamError, },
}
Expand description

A part of a language model stream, tagged by type.

Ordering contract: a stream starts with StreamStart and ends with Finish (or Error); TextDelta parts appear between TextStart and TextEnd with the same id; tool input appears as ToolInputStart, zero or more ToolInputDelta, ToolInputEnd, then ToolCall.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

StreamStart

First part of every stream.

Fields

§warnings: Vec<Warning>

Warnings produced while preparing the call.

§

ResponseMetadata

Response metadata, emitted once known.

Fields

§id: Option<String>

Provider response id.

§timestamp: Option<DateTime<Utc>>

Response timestamp.

§model_id: Option<ModelId>

Model that produced the response.

§

TextStart

Start of a text part.

Fields

§id: PartId

Part id.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

TextDelta

Text increment.

Fields

§id: PartId

Part id.

§delta: String

Appended text.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

TextEnd

End of a text part.

Fields

§id: PartId

Part id.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ReasoningStart

Start of a reasoning part.

Fields

§id: PartId

Part id.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ReasoningDelta

Reasoning increment.

Fields

§id: PartId

Part id.

§delta: String

Appended reasoning text.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ReasoningEnd

End of a reasoning part.

Fields

§id: PartId

Part id.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ToolInputStart

Start of streamed tool input.

Fields

§id: ToolCallId

Tool call id.

§tool_name: ToolName

Name of the tool.

§provider_executed: bool

Whether the provider executes the tool itself.

§dynamic: bool

Whether the tool is dynamic.

§title: Option<String>

Human-readable title for display, if the provider supplies one.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ToolInputDelta

Tool input increment (raw JSON text).

Fields

§id: ToolCallId

Tool call id.

§delta: String

Appended JSON text.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ToolInputEnd

End of streamed tool input.

Fields

§id: ToolCallId

Tool call id.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ToolCall(ToolCall)

A complete tool call.

§

ToolResult(ProviderToolResult)

A provider-executed tool result.

§

ToolApprovalRequest

The provider asks for approval before executing a tool call.

Fields

§approval_id: ApprovalId

Identifier of the approval request.

§tool_call_id: ToolCallId

Identifier of the tool call awaiting approval.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

File

A generated file.

Fields

§data: FileData

File payload.

§media_type: MediaType

Media type of the payload.

§filename: Option<String>

Optional file name.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

ReasoningFile

A reasoning artifact stored as a file.

Fields

§data: FileData

File payload.

§media_type: MediaType

Media type of the payload.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

Source(Source)

A citation source.

§

Custom

Provider-specific content.

Fields

§kind: CustomKind

Kind of the content.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata carrying the payload.

§

Finish

Last part of a successful stream.

Fields

§finish_reason: FinishReason

Why generation stopped.

§usage: Usage

Token usage of the call.

§provider_metadata: Option<ProviderMetadata>

Provider-specific metadata.

§

Raw

A raw provider chunk; only emitted when include_raw_chunks is set.

Fields

§raw_value: JsonValue

The provider chunk as JSON.

§

Error

An error; the stream ends after this part.

Fields

§error: StreamError

The error.

Implementations§

Source§

impl StreamPart

Source

pub fn stream_start() -> Self

Creates a StreamStart without warnings.

Source

pub fn text_delta(id: impl Into<PartId>, delta: impl Into<String>) -> Self

Creates a TextDelta without metadata.

Source

pub fn finish(finish_reason: FinishReason, usage: Usage) -> Self

Creates a Finish without metadata.

Source

pub fn error(error: &ProviderError) -> Self

Creates an Error part from a provider error.

Source

pub fn kind_name(&self) -> &'static str

Returns the wire name of the variant (text-delta, finish, …).

Trait Implementations§

Source§

impl Clone for StreamPart

Source§

fn clone(&self) -> StreamPart

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StreamPart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for StreamPart

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for StreamPart

Source§

fn eq(&self, other: &StreamPart) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for StreamPart

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for StreamPart

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.