pub struct Message {
pub role: Role,
pub contents: Vec<Content>,
pub author_name: Option<String>,
pub message_id: Option<String>,
pub additional_properties: HashMap<String, Value>,
}Expand description
A single chat message: an author role plus an ordered list of content items.
Fields§
§role: Role§contents: Vec<Content>§message_id: Option<String>§additional_properties: HashMap<String, Value>Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: impl Into<Role>, text: impl Into<String>) -> Message
pub fn new(role: impl Into<Role>, text: impl Into<String>) -> Message
Create a message with a single text content item.
Sourcepub fn from_text(role: impl Into<Role>, text: impl Into<String>) -> Message
pub fn from_text(role: impl Into<Role>, text: impl Into<String>) -> Message
Create a message with a single text content item, from an explicit role.
Parity alias for the Python Message(role=…, text=…) constructor.
Sourcepub fn with_contents(role: impl Into<Role>, contents: Vec<Content>) -> Message
pub fn with_contents(role: impl Into<Role>, contents: Vec<Content>) -> Message
Create a message from a role and explicit content items.
Set the author name (builder style).
Sourcepub fn text(&self) -> String
pub fn text(&self) -> String
The concatenated text of all text content items (space-joined).
Returns an empty string when the message carries a provider
refusal (see TextContent::refusal).
A refusal is the model declining to answer; handing its text back here
would present it as the answer, which is how a caller ends up parsing
“I can’t help with that” as its requested JSON. Reach for
Self::refusal_text to read it deliberately, or Self::has_refusal
to branch. Mirrors upstream’s Message.text (#7992).
Sourcepub fn has_refusal(&self) -> bool
pub fn has_refusal(&self) -> bool
Whether any content item is a provider refusal.
Sourcepub fn refusal_text(&self) -> Option<String>
pub fn refusal_text(&self) -> Option<String>
The refusal text, when the model declined — None otherwise.
Several refusal items (which streaming can produce) are space-joined,
matching Self::text’s convention for ordinary text.
Sourcepub fn function_calls(&self) -> Vec<&FunctionCallContent>
pub fn function_calls(&self) -> Vec<&FunctionCallContent>
The function-call content items in this message.
Sourcepub fn function_results(&self) -> Vec<&FunctionResultContent>
pub fn function_results(&self) -> Vec<&FunctionResultContent>
The function-result content items in this message.
Sourcepub fn user_input_requests(&self) -> Vec<&FunctionApprovalRequestContent>
pub fn user_input_requests(&self) -> Vec<&FunctionApprovalRequestContent>
The function-approval request content items in this message.