pub enum Message {
System {
content: String,
id: Option<String>,
name: Option<String>,
additional_kwargs: HashMap<String, Value>,
response_metadata: HashMap<String, Value>,
content_blocks: Vec<ContentBlock>,
},
Human {
content: String,
id: Option<String>,
name: Option<String>,
additional_kwargs: HashMap<String, Value>,
response_metadata: HashMap<String, Value>,
content_blocks: Vec<ContentBlock>,
},
AI {
content: String,
tool_calls: Vec<ToolCall>,
id: Option<String>,
name: Option<String>,
additional_kwargs: HashMap<String, Value>,
response_metadata: HashMap<String, Value>,
content_blocks: Vec<ContentBlock>,
usage_metadata: Option<TokenUsage>,
invalid_tool_calls: Vec<InvalidToolCall>,
},
Tool {
content: String,
tool_call_id: String,
id: Option<String>,
name: Option<String>,
additional_kwargs: HashMap<String, Value>,
response_metadata: HashMap<String, Value>,
content_blocks: Vec<ContentBlock>,
},
Chat {
custom_role: String,
content: String,
id: Option<String>,
name: Option<String>,
additional_kwargs: HashMap<String, Value>,
response_metadata: HashMap<String, Value>,
content_blocks: Vec<ContentBlock>,
},
Remove {
id: String,
},
}Expand description
Represents a chat message. Tagged enum with System, Human, AI, and Tool variants.
Variants§
System
Fields
§
content_blocks: Vec<ContentBlock>Human
Fields
§
content_blocks: Vec<ContentBlock>AI
Fields
§
content_blocks: Vec<ContentBlock>§
usage_metadata: Option<TokenUsage>§
invalid_tool_calls: Vec<InvalidToolCall>Tool
Fields
§
content_blocks: Vec<ContentBlock>Chat
Fields
§
content_blocks: Vec<ContentBlock>Remove
A special message that signals removal of a message by its ID. Used in message history management.
Implementations§
Source§impl Message
impl Message
pub fn system(content: impl Into<String>) -> Message
pub fn human(content: impl Into<String>) -> Message
pub fn ai(content: impl Into<String>) -> Message
pub fn ai_with_tool_calls( content: impl Into<String>, tool_calls: Vec<ToolCall>, ) -> Message
pub fn tool( content: impl Into<String>, tool_call_id: impl Into<String>, ) -> Message
pub fn chat(role: impl Into<String>, content: impl Into<String>) -> Message
Sourcepub fn remove(id: impl Into<String>) -> Message
pub fn remove(id: impl Into<String>) -> Message
Create a Remove message that signals removal of a message by its ID.
pub fn with_id(self, value: impl Into<String>) -> Message
pub fn with_name(self, value: impl Into<String>) -> Message
pub fn with_additional_kwarg( self, key: impl Into<String>, value: Value, ) -> Message
pub fn with_response_metadata_entry( self, key: impl Into<String>, value: Value, ) -> Message
pub fn with_content_blocks(self, blocks: Vec<ContentBlock>) -> Message
pub fn with_usage_metadata(self, usage: TokenUsage) -> Message
pub fn content(&self) -> &str
pub fn role(&self) -> &str
pub fn is_system(&self) -> bool
pub fn is_human(&self) -> bool
pub fn is_ai(&self) -> bool
pub fn is_tool(&self) -> bool
pub fn is_chat(&self) -> bool
pub fn is_remove(&self) -> bool
pub fn tool_calls(&self) -> &[ToolCall]
pub fn tool_call_id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
pub fn additional_kwargs(&self) -> &HashMap<String, Value>
pub fn response_metadata(&self) -> &HashMap<String, Value>
pub fn content_blocks(&self) -> &[ContentBlock]
pub fn usage_metadata(&self) -> Option<&TokenUsage>
pub fn invalid_tool_calls(&self) -> &[InvalidToolCall]
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Message
impl Serialize for Message
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for Message
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.