pub struct Message {
pub role: Role,
pub content: Vec<ContentBlock>,
}Expand description
A message in a conversation.
Fields§
§role: RoleThe role of the message sender
content: Vec<ContentBlock>The content blocks of the message
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, content: Vec<ContentBlock>) -> Self
pub fn new(role: Role, content: Vec<ContentBlock>) -> Self
Create a new message with the given role and content blocks.
Sourcepub fn assistant(text: impl Into<String>) -> Self
pub fn assistant(text: impl Into<String>) -> Self
Create an assistant message with text content.
Sourcepub fn user_with_content(content: Vec<ContentBlock>) -> Self
pub fn user_with_content(content: Vec<ContentBlock>) -> Self
Create a user message with multiple content blocks.
Sourcepub fn assistant_with_content(content: Vec<ContentBlock>) -> Self
pub fn assistant_with_content(content: Vec<ContentBlock>) -> Self
Create an assistant message with multiple content blocks (e.g., tool calls).
Sourcepub fn tool_results(results: Vec<ContentBlock>) -> Self
pub fn tool_results(results: Vec<ContentBlock>) -> Self
Create a tool result message.
Sourcepub fn text_content(&self) -> String
pub fn text_content(&self) -> String
Get all text content from the message concatenated.
Sourcepub fn tool_uses(&self) -> Vec<&ContentBlock>
pub fn tool_uses(&self) -> Vec<&ContentBlock>
Extract all tool use blocks from the message.
Sourcepub fn has_tool_use(&self) -> bool
pub fn has_tool_use(&self) -> bool
Check if the message contains any tool use blocks.
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
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin 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