pub enum Message {
System {
content: String,
},
User {
content: Vec<UserContent>,
},
Assistant(AssistantMessage),
}Expand description
A provider-agnostic chat message.
Messages are role-tagged and may contain one or many content items, including text, images, audio, documents, tool calls, and tool results. Provider modules are responsible for translating these generic messages into provider-native request bodies. That conversion may be lossy when a provider does not support a particular content type.
Variants§
System
System message containing instruction text.
User
User message containing one or more content types defined by UserContent.
Fields
content: Vec<UserContent>Assistant(AssistantMessage)
An assistant turn: its blocks in the order the provider produced them, and where they came from.
Implementations§
Source§impl Message
impl Message
Sourcepub fn rag_text(&self) -> Option<String>
pub fn rag_text(&self) -> Option<String>
Clones the first text block of a user message, or returns None.
Sourcepub fn assistant(text: impl Into<String>) -> Self
pub fn assistant(text: impl Into<String>) -> Self
Creates a hand-built assistant message containing one text block.
Sourcepub fn tool_result(
call: CallId,
name: ToolName,
content: impl Into<String>,
) -> Self
pub fn tool_result( call: CallId, name: ToolName, content: impl Into<String>, ) -> Self
Creates a user message containing a text tool result answering the
call call to the tool name. To answer a call you hold, prefer
ToolCall::result with Self::tool_results.
Sourcepub fn tool_results(results: Vec<ToolResult>) -> Self
pub fn tool_results(results: Vec<ToolResult>) -> Self
Creates a user message carrying results, in order.
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>,
Source§impl From<AssistantContent> for Message
impl From<AssistantContent> for Message
Source§fn from(content: AssistantContent) -> Self
fn from(content: AssistantContent) -> Self
Source§impl From<AssistantMessage> for Message
impl From<AssistantMessage> for Message
Source§fn from(message: AssistantMessage) -> Self
fn from(message: AssistantMessage) -> Self
Source§impl From<Message> for CompletionRequest
impl From<Message> for CompletionRequest
Source§impl From<ToolResult> for Message
impl From<ToolResult> for Message
Source§fn from(value: ToolResult) -> Self
fn from(value: ToolResult) -> Self
Source§impl From<UserContent> for Message
impl From<UserContent> for Message
Source§fn from(content: UserContent) -> Self
fn from(content: UserContent) -> Self
Source§impl From<Vec<AssistantContent>> for Message
impl From<Vec<AssistantContent>> for Message
Source§fn from(content: Vec<AssistantContent>) -> Self
fn from(content: Vec<AssistantContent>) -> Self
Source§impl From<Vec<UserContent>> for Message
impl From<Vec<UserContent>> for Message
Source§fn from(content: Vec<UserContent>) -> Self
fn from(content: Vec<UserContent>) -> Self
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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