pub struct ChatMessage { /* private fields */ }Expand description
A chat message that can be assigned an arbitrary speaker (role).
Use this when you need to specify a custom role that isn’t covered by the standard message types (Human, AI, System, Tool).
This corresponds to ChatMessage in LangChain Python.
Implementations§
Source§impl ChatMessage
impl ChatMessage
Sourcepub fn new(role: impl Into<String>, content: impl Into<String>) -> Self
pub fn new(role: impl Into<String>, content: impl Into<String>) -> Self
Create a new chat message with the given role.
Sourcepub fn with_id(
id: impl Into<String>,
role: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn with_id( id: impl Into<String>, role: impl Into<String>, content: impl Into<String>, ) -> Self
Create a new chat message with an explicit ID.
Use this when deserializing or reconstructing messages where the ID must be preserved.
Sourcepub fn additional_kwargs(&self) -> &HashMap<String, Value>
pub fn additional_kwargs(&self) -> &HashMap<String, Value>
Get additional kwargs.
Sourcepub fn response_metadata(&self) -> &HashMap<String, Value>
pub fn response_metadata(&self) -> &HashMap<String, Value>
Get response metadata.
Sourcepub fn with_response_metadata(
self,
response_metadata: HashMap<String, Value>,
) -> Self
pub fn with_response_metadata( self, response_metadata: HashMap<String, Value>, ) -> Self
Set response metadata.
Trait Implementations§
Source§impl Clone for ChatMessage
impl Clone for ChatMessage
Source§fn clone(&self) -> ChatMessage
fn clone(&self) -> ChatMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChatMessage
impl Debug for 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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<ChatMessage> for BaseMessage
impl From<ChatMessage> for BaseMessage
Source§fn from(msg: ChatMessage) -> Self
fn from(msg: ChatMessage) -> Self
Converts to this type from the input type.
Source§impl PartialEq for ChatMessage
impl PartialEq for ChatMessage
Source§impl Serialize for ChatMessage
impl Serialize for ChatMessage
impl StructuralPartialEq for ChatMessage
Auto Trait Implementations§
impl Freeze for ChatMessage
impl RefUnwindSafe for ChatMessage
impl Send for ChatMessage
impl Sync for ChatMessage
impl Unpin for ChatMessage
impl UnwindSafe for ChatMessage
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