pub struct ChatMessage {
pub role: Role,
pub content: Option<String>,
pub tool_calls: Vec<ToolCall>,
pub tool_call_id: Option<String>,
pub name: Option<String>,
}Expand description
A single chat message.
Serialization follows the OpenAI chat-completions schema:
content may be null on assistant tool-call messages; tool_calls and
tool_call_id are omitted when absent.
Fields§
§role: RoleWho produced this message.
content: Option<String>Text content. None is legal for assistant messages that only carry
tool calls.
tool_calls: Vec<ToolCall>Tool calls requested by the assistant.
tool_call_id: Option<String>Required on role: tool messages: the tool call this answers.
name: Option<String>Optional participant name (multi-agent disambiguation).
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn assistant_tool_calls(tool_calls: Vec<ToolCall>) -> Self
pub fn assistant_tool_calls(tool_calls: Vec<ToolCall>) -> Self
An assistant message requesting tool calls (content may be 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
A tool-result message answering tool_call_id.
Sourcepub fn has_tool_calls(&self) -> bool
pub fn has_tool_calls(&self) -> bool
true if this is an assistant message requesting tool calls.
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§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
Source§impl PartialEq for ChatMessage
impl PartialEq for ChatMessage
Source§impl Serialize for ChatMessage
impl Serialize for ChatMessage
impl StructuralPartialEq for ChatMessage
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