pub enum ContentPart {
Text {
text: String,
},
Image {
media_type: String,
data: String,
},
Audio {
media_type: String,
data: String,
name: Option<String>,
},
Video {
media_type: String,
data: String,
name: Option<String>,
},
Document {
media_type: String,
data: String,
name: Option<String>,
},
}Expand description
A single part of a multimodal message content.
Models like GPT-4o, Claude, and Gemini accept messages with mixed
text and attachment parts. When a ModelMessage contains non-empty
ModelMessage::content_parts, providers serialize each part
according to their native wire format instead of using the plain
ModelMessage::content string.
Variants§
Text
A plain text content block.
Image
An inline image (base64-encoded).
Fields
Audio
An inline audio attachment (base64-encoded).
Fields
Video
An inline video attachment (base64-encoded).
Fields
Document
An inline document attachment (base64-encoded).
Implementations§
Source§impl ContentPart
impl ContentPart
Sourcepub fn is_document(&self) -> bool
pub fn is_document(&self) -> bool
Returns true if this is a document part.
Sourcepub fn attachment_kind(&self) -> Option<AttachmentKind>
pub fn attachment_kind(&self) -> Option<AttachmentKind>
Returns the attachment kind, if this part is an attachment.
Sourcepub fn media_type(&self) -> Option<&str>
pub fn media_type(&self) -> Option<&str>
Returns the MIME type for attachment parts.
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
Optional filename/label for audio, video, or document attachments.
Sourcepub fn text_from_parts(parts: &[ContentPart]) -> String
pub fn text_from_parts(parts: &[ContentPart]) -> String
Returns all text content from a slice of parts, concatenated.
Trait Implementations§
Source§impl Clone for ContentPart
impl Clone for ContentPart
Source§impl Debug for ContentPart
impl Debug for ContentPart
Source§impl<'de> Deserialize<'de> for ContentPart
impl<'de> Deserialize<'de> for ContentPart
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 ContentPart
impl PartialEq for ContentPart
Source§impl Serialize for ContentPart
impl Serialize for ContentPart
impl StructuralPartialEq for ContentPart
Auto Trait Implementations§
impl Freeze for ContentPart
impl RefUnwindSafe for ContentPart
impl Send for ContentPart
impl Sync for ContentPart
impl Unpin for ContentPart
impl UnsafeUnpin for ContentPart
impl UnwindSafe for ContentPart
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