pub struct ChatMessage {
pub role: MessageRole,
pub content: MessageContent,
pub name: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub metadata: HashMap<String, Value>,
pub timestamp: Option<DateTime<Utc>>,
}Expand description
A chat message in a conversation
Fields§
§role: MessageRoleRole of the message sender
content: MessageContentContent of the message
name: Option<String>Optional name of the sender (for user/assistant disambiguation)
tool_calls: Option<Vec<ToolCall>>Tool call information (for assistant messages)
tool_call_id: Option<String>Tool call ID (for tool response messages)
metadata: HashMap<String, Value>Message metadata
timestamp: Option<DateTime<Utc>>Message timestamp
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn new(role: MessageRole, content: impl Into<MessageContent>) -> Self
pub fn new(role: MessageRole, content: impl Into<MessageContent>) -> Self
Create a new chat message
Sourcepub fn system(content: impl Into<MessageContent>) -> Self
pub fn system(content: impl Into<MessageContent>) -> Self
Create a system message
Sourcepub fn user(content: impl Into<MessageContent>) -> Self
pub fn user(content: impl Into<MessageContent>) -> Self
Create a user message
Sourcepub fn assistant(content: impl Into<MessageContent>) -> Self
pub fn assistant(content: impl Into<MessageContent>) -> Self
Create an assistant message
Sourcepub fn tool(
tool_call_id: impl Into<String>,
content: impl Into<MessageContent>,
) -> Self
pub fn tool( tool_call_id: impl Into<String>, content: impl Into<MessageContent>, ) -> Self
Create a tool response message
Sourcepub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
pub fn with_tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
Add tool calls to the message
Sourcepub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
pub fn with_metadata(self, key: impl Into<String>, value: Value) -> Self
Add metadata to the message
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 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