pub struct ChatMessage {
pub role: Role,
pub content: MessageContent,
pub audio: Option<AudioOutput>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
}Expand description
A single message in a conversation thread.
Fields§
§role: Role§content: MessageContentText or multipart content. Deserialised as empty string when the
provider returns null (e.g. GPT-4o audio-only responses).
audio: Option<AudioOutput>Audio output, present only when a model produces audio (e.g. GPT-4o
with modalities: ["audio"]).
tool_calls: Option<Vec<ToolCall>>Tool calls requested by the model in an assistant message.
tool_call_id: Option<String>Tool call ID this message is responding to (used in Role::Tool messages).
Implementations§
Source§impl ChatMessage
impl ChatMessage
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
Create a tool result message to send back after a model requested a tool call.
tool_call_id must match the ToolCall::id from the
assistant message. content is the serialised result of calling the function.
Sourcepub fn user_with_image(
text: impl Into<String>,
image_url: impl Into<String>,
) -> Self
pub fn user_with_image( text: impl Into<String>, image_url: impl Into<String>, ) -> Self
Create a user message containing text followed by a single image.
image_url can be an HTTPS URL or a data:image/...;base64,... URL.
Sourcepub fn with_parts(role: Role, parts: Vec<ContentPart>) -> Self
pub fn with_parts(role: Role, parts: Vec<ContentPart>) -> Self
Create a message with arbitrary content parts.
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more