pub struct Message {
pub role: Role,
pub content: Vec<ContentBlock>,
}Fields§
§role: Role§content: Vec<ContentBlock>Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, content: Vec<ContentBlock>) -> Self
pub fn new(role: Role, content: Vec<ContentBlock>) -> Self
Construct a message from a role and explicit content blocks.
pub fn user(content: impl Into<String>) -> Self
pub fn assistant(content: impl Into<String>) -> Self
pub fn system(content: impl Into<String>) -> Self
Sourcepub fn tool_result(
tool_use_id: impl Into<String>,
content: impl Into<String>,
is_error: bool,
) -> Self
pub fn tool_result( tool_use_id: impl Into<String>, content: impl Into<String>, is_error: bool, ) -> Self
A user message carrying a single tool result (the conventional way to return tool output to the model).
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
Concatenate all text blocks into a single string. Non-text blocks (tool_use / tool_result) are ignored. This is the convenience accessor for callers that only care about textual content.
Sourcepub fn tool_uses(&self) -> impl Iterator<Item = &ContentBlock>
pub fn tool_uses(&self) -> impl Iterator<Item = &ContentBlock>
All tool_use blocks in this message.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
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
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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