pub enum Message {
System(SystemMessage),
User(UserMessage),
Assistant(AssistantMessage),
Tool(ToolMessage),
Function(FunctionMessage),
Developer(DeveloperMessage),
}Expand description
A message in the conversation, tagged by role.
Construct messages through the convenience constructors
(Message::system, Message::user, Message::assistant,
Message::tool, Message::function, Message::developer) or by
building the payload structs directly (Message::User(UserMessage { ..Default::default() })), which stays source-compatible when new
optional fields are added.
Deserialization of an unknown role is an error: a message with an
unrecognized role cannot be forwarded, so it is treated as invalid input
rather than silently mapped onto a catch-all.
Variants§
System(SystemMessage)
The role of the message author is system.
The field { role = "system" } is added automatically.
User(UserMessage)
The role of the message author is user.
The field { role = "user" } is added automatically.
Assistant(AssistantMessage)
The role of the message author is assistant.
The field { role = "assistant" } is added automatically.
Tool(ToolMessage)
The role of the message author is tool.
The field { role = "tool" } is added automatically.
Function(FunctionMessage)
The role of the message author is function.
The field { role = "function" } is added automatically.
Developer(DeveloperMessage)
The role of the message author is developer.
The field { role = "developer" } is added automatically.
Implementations§
Source§impl Message
impl Message
Sourcepub fn system(content: impl Into<MessageContent>) -> Self
pub fn system(content: impl Into<MessageContent>) -> Self
A system message with the given content: plain text, or an array of text content parts.
Sourcepub fn user(content: impl Into<MessageContent>) -> Self
pub fn user(content: impl Into<MessageContent>) -> Self
A user message with the given content: plain text, or an array of
multimodal content parts (text, image_url, input_audio,
file).
Sourcepub fn assistant(content: impl Into<String>) -> Self
pub fn assistant(content: impl Into<String>) -> Self
An assistant message with the given text content. Build
AssistantMessage directly for tool calls, audio, or reasoning
content.
Sourcepub fn tool(
content: impl Into<MessageContent>,
tool_call_id: impl Into<String>,
) -> Self
pub fn tool( content: impl Into<MessageContent>, tool_call_id: impl Into<String>, ) -> Self
A tool message responding to the tool call with the given 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
A deprecated function message responding to the named function
call.
Sourcepub fn developer(content: impl Into<MessageContent>) -> Self
pub fn developer(content: impl Into<MessageContent>) -> Self
A developer message with the given content: plain text, or an array of text content parts.