pub struct ChatMessage {
pub role: Role,
pub content: Option<String>,
pub reasoning_content: Option<String>,
pub refusal: Option<String>,
pub name: Option<String>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
}Expand description
A message in a chat conversation.
Fields§
§role: RoleRole of the message author.
content: Option<String>Text contents of the message. Optional when assistant returns tool calls.
reasoning_content: Option<String>Reasoning or chain-of-thought tokens from reasoning models (e.g. DeepSeek-R1, o1/o3).
refusal: Option<String>Refusal message if the model refused to respond.
name: Option<String>Optional participant name.
tool_calls: Option<Vec<ToolCall>>Tool calls made by the assistant, if any.
tool_call_id: Option<String>ID of the tool call this message is responding to (for role = Role::Tool).
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn developer(content: impl Into<String>) -> Self
pub fn developer(content: impl Into<String>) -> Self
Construct a new developer instruction message for reasoning models.
Sourcepub fn assistant_with_reasoning(
content: impl Into<String>,
reasoning: impl Into<String>,
) -> Self
pub fn assistant_with_reasoning( content: impl Into<String>, reasoning: impl Into<String>, ) -> Self
Construct a new assistant message containing reasoning content.
Sourcepub fn assistant_tool_calls(tool_calls: Vec<ToolCall>) -> Self
pub fn assistant_tool_calls(tool_calls: Vec<ToolCall>) -> Self
Construct a new assistant message containing tool calls.
Sourcepub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
Construct a new tool reply message for a given tool call ID.
Sourcepub fn function(name: impl Into<String>, content: impl Into<String>) -> Self
pub fn function(name: impl Into<String>, content: impl Into<String>) -> Self
Construct a new legacy function reply message.
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Set an optional participant name for the message.
Sourcepub fn refusal(self, refusal: impl Into<String>) -> Self
pub fn refusal(self, refusal: impl Into<String>) -> Self
Set an optional refusal message for an assistant reply.
Sourcepub fn reasoning_content(self, reasoning: impl Into<String>) -> Self
pub fn reasoning_content(self, reasoning: impl Into<String>) -> Self
Set reasoning content (thinking tokens) for the message.
Sourcepub fn tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
pub fn tool_calls(self, tool_calls: Vec<ToolCall>) -> Self
Attach tool calls to the message.
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more