Skip to main content

Item

Enum Item 

Source
pub enum Item {
    Text {
        text: String,
        kind: TextKind,
    },
    Message(Message),
    Bytes(Vec<u8>),
    Tensor(Tensor),
    Image(Image),
    Audio(Audio),
    ToolCall(ToolCall),
    ToolResult(ToolResult),
    SpeechSegment(SpeechSegment),
    SpeechResult(SpeechResult),
}
Expand description

A single unit of input or output data exchanged with a Session.

Item is a pure-data, owned value: it holds no native handle and is Send + Sync + Clone. Construct items with the associated functions (e.g. Item::text, Item::user_message, Item::image_data) or the struct variants directly, and inspect them by pattern matching.

Variants§

§

Text

UTF-8 text of a given TextKind.

Fields

§text: String

The text content.

§kind: TextKind

The text subtype.

§

Message(Message)

A chat message with nested content parts.

§

Bytes(Vec<u8>)

An opaque byte buffer.

§

Tensor(Tensor)

A numeric tensor (e.g. an embedding vector).

§

Image(Image)

An image, inline or by URI.

§

Audio(Audio)

An audio clip, inline or by URI.

§

ToolCall(ToolCall)

A model-issued tool/function call.

§

ToolResult(ToolResult)

The result of executing a tool/function call.

§

SpeechSegment(SpeechSegment)

A speech-recognition segment (output-only).

§

SpeechResult(SpeechResult)

A speech-recognition result (output-only).

Implementations§

Source§

impl Item

Source

pub fn item_type(&self) -> ItemType

The ItemType discriminant of this item.

Source

pub fn text(text: impl Into<String>) -> Self

A default-kind Item::Text.

Source

pub fn reasoning(text: impl Into<String>) -> Self

A reasoning / chain-of-thought Item::Text.

Source

pub fn message(role: MessageRole, content: impl Into<Vec<Item>>) -> Self

A Item::Message with the given role and content parts.

Source

pub fn system_message(content: impl Into<Vec<Item>>) -> Self

A system Item::Message.

Source

pub fn user_message(content: impl Into<Vec<Item>>) -> Self

A user Item::Message.

Source

pub fn assistant_message(content: impl Into<Vec<Item>>) -> Self

An assistant Item::Message.

Source

pub fn developer_message(content: impl Into<Vec<Item>>) -> Self

A developer Item::Message.

Source

pub fn tool_message(content: impl Into<Vec<Item>>) -> Self

A tool Item::Message.

Source

pub fn bytes(data: impl Into<Vec<u8>>) -> Self

An Item::Bytes carrying an opaque byte buffer.

Source

pub fn tensor( data_type: TensorDataType, shape: impl Into<Vec<i64>>, data: impl Into<Vec<u8>>, ) -> Self

An Item::Tensor from a data type, shape, and raw element bytes.

Source

pub fn float_tensor(shape: impl Into<Vec<i64>>, data: &[f32]) -> Self

A TensorDataType::Float Item::Tensor from f32 elements.

Source

pub fn image_data( data: impl Into<Vec<u8>>, format: Option<impl Into<String>>, ) -> Self

An Item::Image from inline bytes and an optional format hint.

Source

pub fn image_uri( uri: impl Into<String>, format: Option<impl Into<String>>, ) -> Self

An Item::Image referencing external content by URI.

Source

pub fn audio_data( data: impl Into<Vec<u8>>, format: Option<impl Into<String>>, sample_rate: i32, channels: i32, ) -> Self

An Item::Audio from inline bytes, format hint, and PCM layout.

Source

pub fn audio_uri( uri: impl Into<String>, format: Option<impl Into<String>>, sample_rate: i32, channels: i32, ) -> Self

An Item::Audio referencing external content by URI.

Source

pub fn tool_call( call_id: impl Into<String>, name: impl Into<String>, arguments: impl Into<String>, ) -> Self

Source

pub fn tool_result( call_id: impl Into<String>, result: impl Into<String>, ) -> Self

Source

pub fn as_text(&self) -> Option<&str>

The text content, if this is a Item::Text.

Source

pub fn as_message(&self) -> Option<&Message>

The Message, if this is a Item::Message.

Source

pub fn as_tensor(&self) -> Option<&Tensor>

The Tensor, if this is a Item::Tensor.

Source

pub fn as_tool_call(&self) -> Option<&ToolCall>

The ToolCall, if this is a Item::ToolCall.

Source

pub fn as_speech_result(&self) -> Option<&SpeechResult>

The SpeechResult, if this is a Item::SpeechResult.

Trait Implementations§

Source§

impl Clone for Item

Source§

fn clone(&self) -> Item

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 Item

Source§

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

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

impl PartialEq for Item

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Item

Auto Trait Implementations§

§

impl Freeze for Item

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnsafeUnpin for Item

§

impl UnwindSafe for Item

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more