#[non_exhaustive]pub enum Message {
System {
id: String,
meta: MessageMeta,
content: String,
},
User {
id: String,
meta: MessageMeta,
content: Vec<ContentPart>,
},
Assistant {
id: String,
meta: MessageMeta,
content: Vec<AssistantContent>,
},
Tool {
id: String,
meta: MessageMeta,
tool_call_id: String,
content: Vec<ContentPart>,
},
}Expand description
A single message in the conversation history.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Implementations§
Source§impl Message
impl Message
pub fn system(content: &str) -> Message
pub fn user(content: &str) -> Message
pub fn assistant(content: &str) -> Message
pub fn assistant_with_tool_call(content: &str, call: ToolCallRef) -> Message
pub fn assistant_with_tool_calls( content: &str, calls: Vec<ToolCallRef>, ) -> Message
pub fn tool_result(id: impl Into<String>, content: &str) -> Message
Sourcepub fn user_with_parts(parts: Vec<ContentPart>) -> Message
pub fn user_with_parts(parts: Vec<ContentPart>) -> Message
Construct a User message from an arbitrary list of content parts. Order is preserved on the wire.
Sourcepub fn tool_result_with_parts(
tool_call_id: impl Into<String>,
parts: Vec<ContentPart>,
) -> Message
pub fn tool_result_with_parts( tool_call_id: impl Into<String>, parts: Vec<ContentPart>, ) -> Message
Construct a Tool-result message from an arbitrary list of content parts.
Sourcepub fn user_with_image_base64(
prompt: &str,
media_type: impl Into<String>,
data: impl Into<String>,
) -> Message
pub fn user_with_image_base64( prompt: &str, media_type: impl Into<String>, data: impl Into<String>, ) -> Message
Convenience: User message with a text prompt followed by a base64 image.
If prompt is empty, the text part is omitted.
Sourcepub fn user_with_image_url(prompt: &str, url: impl Into<String>) -> Message
pub fn user_with_image_url(prompt: &str, url: impl Into<String>) -> Message
Convenience: User message with a text prompt followed by a URL image.
If prompt is empty, the text part is omitted.
Sourcepub fn tool_result_with_image_base64(
tool_call_id: impl Into<String>,
text: &str,
media_type: impl Into<String>,
data: impl Into<String>,
) -> Message
pub fn tool_result_with_image_base64( tool_call_id: impl Into<String>, text: &str, media_type: impl Into<String>, data: impl Into<String>, ) -> Message
Convenience: Tool result with a leading text followed by a base64 image.
If text is empty, the text part is omitted.
Sourcepub fn tool_result_with_image_url(
tool_call_id: impl Into<String>,
text: &str,
url: impl Into<String>,
) -> Message
pub fn tool_result_with_image_url( tool_call_id: impl Into<String>, text: &str, url: impl Into<String>, ) -> Message
Convenience: Tool result with a leading text followed by a URL image.
If text is empty, the text part is omitted.
Sourcepub fn user_with_document_base64(
prompt: &str,
media_type: impl Into<String>,
data: impl Into<String>,
) -> Message
pub fn user_with_document_base64( prompt: &str, media_type: impl Into<String>, data: impl Into<String>, ) -> Message
Convenience: User message with a text prompt followed by a base64 document.
If prompt is empty, the text part is omitted.
Sourcepub fn user_with_document_url(prompt: &str, url: impl Into<String>) -> Message
pub fn user_with_document_url(prompt: &str, url: impl Into<String>) -> Message
Convenience: User message with a text prompt followed by a URL document.
If prompt is empty, the text part is omitted.
Sourcepub fn user_with_pdf_base64(prompt: &str, data: impl Into<String>) -> Message
pub fn user_with_pdf_base64(prompt: &str, data: impl Into<String>) -> Message
Hardcodes application/pdf as the media type. If prompt is empty, the
text part is omitted.
Sourcepub fn user_with_pdf_url(prompt: &str, url: impl Into<String>) -> Message
pub fn user_with_pdf_url(prompt: &str, url: impl Into<String>) -> Message
Convenience: User message with a text prompt followed by a PDF URL.
If prompt is empty, the text part is omitted.
pub fn role(&self) -> Role
pub fn id(&self) -> &String
pub fn meta(&self) -> &MessageMeta
pub fn meta_mut(&mut self) -> &mut MessageMeta
Sourcepub fn approx_visible_chars(&self) -> usize
pub fn approx_visible_chars(&self) -> usize
Approximate number of prompt-visible characters for token estimation.
Includes all currently-known assistant block types so estimators do not
undercount when non-Text blocks (e.g. Reasoning, Compaction) are
present. Unknown future block variants fall back to serialized length.
Sourcepub fn tool_calls(&self) -> Vec<&ToolCallRef>
pub fn tool_calls(&self) -> Vec<&ToolCallRef>
Tool call references on an assistant message; empty for other roles.
Sourcepub fn tool_call_id(&self) -> Option<&str>
pub fn tool_call_id(&self) -> Option<&str>
For Tool role messages, the id of the tool call this is a result for.