#[non_exhaustive]pub enum Message {
System {
content: Vec<ContentPart>,
},
User {
content: Vec<ContentPart>,
},
Assistant {
content: Vec<ContentPart>,
tool_calls: Vec<ToolCall>,
},
Tool {
tool_call_id: String,
name: String,
content: Vec<ContentPart>,
},
}Expand description
Chat message role and content.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
System
System instruction message.
Fields
§
content: Vec<ContentPart>Message content parts.
User
User message.
Fields
§
content: Vec<ContentPart>Message content parts.
Assistant
Assistant message, optionally including tool calls.
Fields
§
content: Vec<ContentPart>Message content parts.
Tool
Tool result message.
Implementations§
Source§impl Message
impl Message
Sourcepub fn system_text(text: impl Into<String>) -> Self
pub fn system_text(text: impl Into<String>) -> Self
Creates a system text message.
Sourcepub fn assistant_text(text: impl Into<String>) -> Self
pub fn assistant_text(text: impl Into<String>) -> Self
Creates an assistant text message without tool calls.
Sourcepub fn tool_text(
tool_call_id: impl Into<String>,
name: impl Into<String>,
text: impl Into<String>,
) -> Self
pub fn tool_text( tool_call_id: impl Into<String>, name: impl Into<String>, text: impl Into<String>, ) -> Self
Creates a tool result message.
Sourcepub fn tool_calls(&self) -> &[ToolCall]
pub fn tool_calls(&self) -> &[ToolCall]
Returns the tool calls from an Assistant message, or empty slice.
Sourcepub fn mark_cache_breakpoint(self) -> Self
pub fn mark_cache_breakpoint(self) -> Self
Marks the last content part of this message as a cache breakpoint.
If the message has no content parts, the marker is a no-op. If the last content part already has a cache control, it is replaced.
This is a convenience for callers that want to place a cache breakpoint at the end of a message (the most common case).
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 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