#[non_exhaustive]pub enum ContentPart {
Text {
text: String,
},
Image {
source: ImageSource,
},
Document {
source: DocumentSource,
},
ToolCall(ToolCall),
ToolResult(ToolResult),
}Expand description
One piece of a message.
A message is a sequence of parts rather than a string because a turn can legitimately mix prose, an attachment and the tool exchange that preceded it.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text
Plain text.
Image
An image. Requires
vision.
Fields
source: ImageSourceWhere the bytes come from.
Document
A document — a PDF, a spreadsheet, a plain-text attachment. Requires
documents,
which is declared separately from vision because accepting a PNG says
nothing about accepting a PDF.
Fields
source: DocumentSourceWhere the bytes come from, and what they are.
ToolCall(ToolCall)
A call the model made (in an assistant message).
ToolResult(ToolResult)
A result the runtime returned (in a tool message).
Implementations§
Source§impl ContentPart
impl ContentPart
Sourcepub fn image_base64(
media_type: impl Into<String>,
data: impl Into<String>,
) -> Self
pub fn image_base64( media_type: impl Into<String>, data: impl Into<String>, ) -> Self
An inline image.
Sourcepub fn inline_bytes(media_type: impl Into<String>, bytes: &[u8]) -> Self
pub fn inline_bytes(media_type: impl Into<String>, bytes: &[u8]) -> Self
An inline part built from raw bytes, encoded here.
Which of the two it becomes is decided by the media type, because the
distinction the provider layer draws is exactly that one: image/* is an
image, everything else is a document. A caller holding bytes should not
have to know that accepting a PNG says nothing about accepting a PDF —
the capability requirements are derived from the part, so the router does
that part.
Every inline form in this module takes base64 without a data-URI prefix, which is a rule a caller can only get wrong. So the encoding lives here, beside the contract that asks for it, rather than in every application that has a file.
Sourcepub fn document_url(
url: impl Into<String>,
media_type: impl Into<String>,
) -> Self
pub fn document_url( url: impl Into<String>, media_type: impl Into<String>, ) -> Self
A document the provider fetches from a URL, with its media type stated.
Sourcepub fn document_base64(
media_type: impl Into<String>,
data: impl Into<String>,
) -> Self
pub fn document_base64( media_type: impl Into<String>, data: impl Into<String>, ) -> Self
An inline document.
Sourcepub fn as_tool_call(&self) -> Option<&ToolCall>
pub fn as_tool_call(&self) -> Option<&ToolCall>
Borrows the call, when this is a tool call.
Sourcepub fn as_document(&self) -> Option<&DocumentSource>
pub fn as_document(&self) -> Option<&DocumentSource>
Borrows the source, when this is a document part.
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>,
impl Eq for ContentPart
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.