pub enum ContentPart {
Text {
text: String,
},
Image {
source: ImageSource,
mime: String,
},
Audio {
source: AudioSource,
mime: String,
},
}Expand description
One non-text part of a multimodal message.
Variants§
Text
Plain text part. Most messages don’t need this — the textual
content field on the message itself is the standard way to carry
text. Provided here for symmetry with multi-text-block providers.
Image
An image, by URL or inline base64.
Fields
§
source: ImageSourceWhere the image bytes come from.
Audio
Audio, by URL or inline base64.
Implementations§
Source§impl ContentPart
impl ContentPart
Sourcepub fn to_openai(&self) -> Value
pub fn to_openai(&self) -> Value
Serialize as an OpenAI Chat Completions content part.
- Text →
{"type":"text","text":"..."} - Image →
{"type":"image_url","image_url":{"url":"..."}}(URL ordata:URI for base64). - Audio →
{"type":"input_audio","input_audio":{"data":"...","format":"..."}}
Sourcepub fn from_openai(v: &Value) -> Option<Self>
pub fn from_openai(v: &Value) -> Option<Self>
Parse an OpenAI content part back into ContentPart.
Sourcepub fn to_anthropic(&self) -> Value
pub fn to_anthropic(&self) -> Value
Serialize as an Anthropic content block.
- Text →
{"type":"text","text":"..."} - Image →
{"type":"image","source":{"type":"url","url":...}}or{"type":"image","source":{"type":"base64","media_type":"...","data":"..."}} - Audio → not supported by Anthropic at time of writing; emitted
as an Anthropic
textblock describing the audio reference.
Sourcepub fn from_anthropic(v: &Value) -> Option<Self>
pub fn from_anthropic(v: &Value) -> Option<Self>
Parse an Anthropic content block back into ContentPart.
Sourcepub fn to_gemini(&self) -> Value
pub fn to_gemini(&self) -> Value
Serialize as a Gemini Part.
- Text →
{"text":"..."} - Image →
{"inline_data":{"mime_type":"...","data":"..."}}for base64;{"file_data":{"mime_type":"...","file_uri":"..."}}for URL. - Audio → same shape as image (Gemini accepts audio inline/file_data).
Sourcepub fn from_gemini(v: &Value) -> Option<Self>
pub fn from_gemini(v: &Value) -> Option<Self>
Parse a Gemini Part back into ContentPart.
Trait Implementations§
Source§impl Clone for ContentPart
impl Clone for ContentPart
Source§fn clone(&self) -> ContentPart
fn clone(&self) -> ContentPart
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for ContentPart
impl PartialEq for ContentPart
Source§fn eq(&self, other: &ContentPart) -> bool
fn eq(&self, other: &ContentPart) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ContentPart
impl Serialize for ContentPart
impl Eq 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
Mutably borrows from an owned value. Read more