pub struct ChatMessage {
pub role: String,
pub content: Option<String>,
pub multimodal_content: Option<Vec<ContentPart>>,
pub tool_calls: Option<Vec<MessageToolCall>>,
pub tool_call_id: Option<String>,
}Expand description
Chat message (OpenAI shape: role, optional content, optional tool_calls, optional tool_call_id for role “tool”)
Fields§
§role: String§content: Option<String>Text-only content (for backward compatibility)
multimodal_content: Option<Vec<ContentPart>>Multimodal content (text + images) - providers should prefer this if present
tool_calls: Option<Vec<MessageToolCall>>§tool_call_id: Option<String>Implementations§
Source§impl ChatMessage
impl ChatMessage
pub fn system(content: impl Into<String>) -> Self
pub fn user(content: impl Into<String>) -> Self
Sourcepub fn user_with_images<S: Into<String>>(
text: S,
images: Vec<(Vec<u8>, String)>,
) -> Self
pub fn user_with_images<S: Into<String>>( text: S, images: Vec<(Vec<u8>, String)>, ) -> Self
User message with images (multimodal content for vision models)
Creates a user message with text and one or more images. The images should be provided as base64-encoded data with their MIME type.
§Example
ⓘ
let msg = ChatMessage::user_with_images(
"Describe this image",
vec![("data:image/jpeg;base64,...", "image/jpeg")],
);pub fn assistant(content: impl Into<String>) -> Self
Sourcepub fn assistant_with_tool_calls(
content: Option<String>,
tool_calls: Vec<MessageToolCall>,
) -> Self
pub fn assistant_with_tool_calls( content: Option<String>, tool_calls: Vec<MessageToolCall>, ) -> Self
Assistant message with tool calls (content may be None or empty)
Sourcepub fn tool_result(
tool_call_id: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn tool_result( tool_call_id: impl Into<String>, content: impl Into<String>, ) -> Self
Tool result message (role “tool”)
Sourcepub fn has_images(&self) -> bool
pub fn has_images(&self) -> bool
Check if this message contains multimodal content (images)
Sourcepub fn effective_content(&self) -> MessageContent
pub fn effective_content(&self) -> MessageContent
Get the effective content for serialization to providers Returns either multimodal content parts or text-only content
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChatMessage
impl Debug for ChatMessage
Source§impl<'de> Deserialize<'de> for ChatMessage
impl<'de> Deserialize<'de> for ChatMessage
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 ChatMessage
impl RefUnwindSafe for ChatMessage
impl Send for ChatMessage
impl Sync for ChatMessage
impl Unpin for ChatMessage
impl UnsafeUnpin for ChatMessage
impl UnwindSafe for ChatMessage
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