pub struct ChatMessage {
pub role: String,
pub content: Option<MessageContent>,
pub tool_calls: Option<Value>,
pub extra: Map<String, Value>,
}Expand description
A chat message for transformation.
content uses MessageContent which accepts both a plain JSON string
and a JSON array of content-part objects during deserialization, preserving
the original form during serialization.
§Lossless round-trip
transform_messages_for_capabilities is reached by deserializing a
client’s messages array into this type and re-serializing the result, so
any field this struct does not model would be deleted on the way
through. Three fields are named because the transform reads them;
everything else — tool_call_id, name, vendor extensions — is carried
verbatim in extra and never interpreted.
This is not hypothetical tidiness. tool_call_id is required by the Jinja
templates of exactly the models that set
REQUIRES_STRICT_TURNS — the
Mistral family — so dropping it would break tool calling on the models the
transform exists to serve.
Fields§
§role: String§content: Option<MessageContent>§tool_calls: Option<Value>§extra: Map<String, Value>Every other key the message carried, passed through untouched.
Flattened, so these sit at the message’s top level on the wire exactly where they came from. An empty map serializes to nothing.
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcefn merge_into(&mut self, other: Self)
fn merge_into(&mut self, other: Self)
Merge other into self in-place.
Used during strict-turn coalescing to combine consecutive same-role
messages. Content is merged via MessageContent::merge_with; tool
calls are concatenated as JSON arrays.
For extra the surviving message’s keys win and only
absent ones are adopted from other. Only user / assistant
messages are ever merged and those rarely carry extras, so this is a
tie-break rule rather than a load-bearing one — but silently preferring
the later message’s name over the one already in the merged text
would be the surprising choice.
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatMessage
impl Debug for ChatMessage
Source§impl Default for ChatMessage
impl Default for ChatMessage
Source§fn default() -> ChatMessage
fn default() -> 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>,
Source§impl PartialEq for ChatMessage
impl PartialEq for ChatMessage
Source§fn eq(&self, other: &ChatMessage) -> bool
fn eq(&self, other: &ChatMessage) -> bool
self and other values to be equal, and is used by ==.