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 final_answer(&self) -> Option<String>
pub fn final_answer(&self) -> Option<String>
The text of a final answer: the text parts of the model’s message,
joined by blank lines and trimmed. None when this is not the
model’s message, still asks for tool calls, or has no text.
use rig_core::message::Message;
assert_eq!(Message::assistant(" Done. ").final_answer().as_deref(), Some("Done."));
assert_eq!(Message::user("Done.").final_answer(), None);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 user(text: impl Into<String>) -> Message
pub fn user(text: impl Into<String>) -> Message
Creates a user message containing one text block.
Sourcepub fn assistant(text: impl Into<String>) -> Message
pub fn assistant(text: impl Into<String>) -> Message
Creates a hand-built assistant message containing one text block.
Sourcepub fn tool_result(
call: CallId,
name: ToolName,
content: impl Into<String>,
) -> Message
pub fn tool_result( call: CallId, name: ToolName, content: impl Into<String>, ) -> Message
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>) -> Message
pub fn tool_results(results: Vec<ToolResult>) -> Message
Creates a user message carrying results, in order.
Sourcepub fn results(&self) -> impl Iterator<Item = &ToolResult>
pub fn results(&self) -> impl Iterator<Item = &ToolResult>
The tool results a user message carries, in order; none for other roles.
Sourcepub fn images(&self) -> impl Iterator<Item = &Image>
pub fn images(&self) -> impl Iterator<Item = &Image>
The images of this message, in order: a user message’s own and those of its tool results, or an assistant turn’s.
Sourcepub fn images_mut(&mut self) -> impl Iterator<Item = &mut Image>
pub fn images_mut(&mut self) -> impl Iterator<Item = &mut Image>
The images of this message, as Self::images, to change in place.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl From<Arc<Message>> for Message
A shared message, such as a conversation’s, taken out of its Arc:
moved when nothing else holds it, else copied.
impl From<Arc<Message>> for Message
A shared message, such as a conversation’s, taken out of its Arc:
moved when nothing else holds it, else copied.