pub struct Message {
pub role: Role,
pub content: Vec<ContentPart>,
pub tool_calls: Option<Vec<ToolCall>>,
pub tool_call_id: Option<String>,
pub name: Option<String>,
}Expand description
A single message in the LLM conversation history.
content is now Vec<ContentPart> to support multimodal messages
(text + images) and Anthropic-style tool content blocks.
For the common single-text-message case the API still sees a plain string
thanks to the custom serialize_content_parts serializer.
Fields§
§role: Role§content: Vec<ContentPart>Message body — one or more content parts.
Use text_content() to extract plain text.
NOTE: serialization is handled by a custom serializer below.
tool_calls: Option<Vec<ToolCall>>§tool_call_id: Option<String>§name: Option<String>Implementations§
Source§impl Message
impl Message
Sourcepub fn system(content: impl Into<String>) -> Self
pub fn system(content: impl Into<String>) -> Self
Create a system message with plain text content.
Sourcepub fn assistant(
content: Option<String>,
tool_calls: Option<Vec<ToolCall>>,
) -> Self
pub fn assistant( content: Option<String>, tool_calls: Option<Vec<ToolCall>>, ) -> Self
Create an assistant message.
content is Option<String> here for backwards compatibility with
callers that had content: Option<String>. Pass None when the
response contains only tool calls.
Sourcepub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
Create a tool-result message.
Sourcepub fn text_content(&self) -> Option<String>
pub fn text_content(&self) -> Option<String>
Extract all plain text from this message’s content parts.
Concatenates every ContentPart::Text in order, joining with \n
when there are multiple text parts. Returns None if there are no
text parts (e.g. a message containing only images or tool results).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
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>,
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more