pub enum UserContent {
Text(String),
Parts(Vec<InputContent>),
}Expand description
The body of a user message: either a bare string or an ordered list of multimodal parts.
Variants§
Implementations§
Source§impl UserContent
impl UserContent
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
The text, when the content is a plain string.
None for multimodal content, even when every part of it happens to be
text: this borrows, and joining parts cannot. Reach for
UserContent::to_text when any text will do.
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Every text part, in order, joined with newlines.
Non-text parts are dropped rather than described: an agent that does not handle images wants the caption, not a placeholder it has to strip.
use ag_ui::{InputContent, InputContentSource, MediaInputContent, UserContent};
let plain = UserContent::from("what is the weather?");
assert_eq!(plain.as_text(), Some("what is the weather?"));
assert_eq!(plain.to_text(), "what is the weather?");
let image = MediaInputContent::new(InputContentSource::Url {
value: "https://example.com/cat.png".into(),
mime_type: None,
});
let mixed = UserContent::from(vec![
InputContent::text("what is this?"),
InputContent::Image(image),
InputContent::text("be brief"),
]);
assert_eq!(mixed.as_text(), None);
assert_eq!(mixed.to_text(), "what is this?\nbe brief");Trait Implementations§
Source§impl Clone for UserContent
impl Clone for UserContent
Source§fn clone(&self) -> UserContent
fn clone(&self) -> UserContent
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 ComposeSchema for UserContent
impl ComposeSchema for UserContent
Source§impl Debug for UserContent
impl Debug for UserContent
Source§impl Default for UserContent
impl Default for UserContent
Source§impl<'de> Deserialize<'de> for UserContent
impl<'de> Deserialize<'de> for UserContent
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 From<&str> for UserContent
impl From<&str> for UserContent
Source§impl From<String> for UserContent
impl From<String> for UserContent
Source§impl From<Vec<InputContent>> for UserContent
impl From<Vec<InputContent>> for UserContent
Source§fn from(value: Vec<InputContent>) -> Self
fn from(value: Vec<InputContent>) -> Self
Converts to this type from the input type.
Source§impl JsonSchema for UserContent
impl JsonSchema for UserContent
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
Whether JSON Schemas generated for this type should be included directly in parent schemas,
rather than being re-used where possible using the
$ref keyword. Read moreSource§impl PartialEq for UserContent
impl PartialEq for UserContent
Source§fn eq(&self, other: &UserContent) -> bool
fn eq(&self, other: &UserContent) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for UserContent
impl Serialize for UserContent
impl StructuralPartialEq for UserContent
Auto Trait Implementations§
impl Freeze for UserContent
impl RefUnwindSafe for UserContent
impl Send for UserContent
impl Sync for UserContent
impl Unpin for UserContent
impl UnsafeUnpin for UserContent
impl UnwindSafe for UserContent
Blanket Implementations§
impl<T> AgentState for T
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