#[non_exhaustive]pub enum Content {
Text {
text: String,
},
Image(Image),
Document(Document),
Audio(Audio),
Video(Video),
Multi {
parts: Vec<ContentPrimitive>,
},
}Expand description
Chat input content, mirroring the Python SDK’s
Content = str | Image | Document | Audio | Video | list[ContentPrimitive].
This is the top-level union type accepted by crate::agent::AgentHandle::chat().
Unlike ContentPrimitive, it includes the Multi variant
for compound multimodal inputs. Scalar variants mirror ContentPrimitive
for convenience so callers do not have to wrap a single item in a list.
Use From<&str> or From<String> to create text content ergonomically:
let content: Content = "hello".into();Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Text
Plain text content (backward-compatible with chat("hello")).
Image(Image)
An image attachment.
Document(Document)
A document attachment.
Audio(Audio)
An audio attachment.
Video(Video)
A video attachment.
Multi
A list of content primitives (multimodal).
Fields
parts: Vec<ContentPrimitive>The individual content elements.
Implementations§
Source§impl Content
impl Content
Sourcepub fn text(s: impl Into<String>) -> Self
pub fn text(s: impl Into<String>) -> Self
Creates a Content::Text variant from any string-like value.
This is a convenience constructor equivalent to Content::Text { text: s.into() }.
§Examples
let c = Content::text("hello");
assert!(c.is_text());
assert_eq!(c.as_text(), Some("hello"));Sourcepub const fn is_text(&self) -> bool
pub const fn is_text(&self) -> bool
Returns true if this content is a Content::Text variant.
§Examples
assert!(Content::text("hi").is_text());
assert!(!Content::Image(Image::png(vec![1])).is_text());Sourcepub const fn as_text(&self) -> Option<&str>
pub const fn as_text(&self) -> Option<&str>
Returns the text content if this is a Content::Text variant,
or None otherwise.
§Examples
let text_content = Content::text("hello");
assert_eq!(text_content.as_text(), Some("hello"));
let image_content = Content::Image(Image::png(vec![1]));
assert_eq!(image_content.as_text(), None);Trait Implementations§
Source§impl Default for Content
impl Default for Content
Source§fn default() -> Self
fn default() -> Self
Defaults to an empty Content::Text variant.
§Examples
let c = Content::default();
assert_eq!(c.as_text(), Some(""));