pub struct ChatMessage<Body> { /* private fields */ }
Expand description
The ChatMessage
struct represents a chat message.
It has two fields:
role
: The role of the message sender.body
: The body of the message.
Implementations§
Source§impl<Body> ChatMessage<Body>
impl<Body> ChatMessage<Body>
Sourcepub fn new(role: ChatRole, body: Body) -> Self
pub fn new(role: ChatRole, body: Body) -> Self
Creates a new chat message.
§Arguments
role
- The role of the message sender.body
- The body of the message.
Sourcepub fn map<U, F: FnOnce(&Body) -> U>(&self, f: F) -> ChatMessage<U>
pub fn map<U, F: FnOnce(&Body) -> U>(&self, f: F) -> ChatMessage<U>
Maps the body of the chat message using the provided function f
.
§Arguments
f
- The function to apply to the message body.
§Example
use llm_chain::prompt::{ChatMessage, ChatRole};
let msg = ChatMessage::new(ChatRole::Assistant, "Hello!");
let mapped_msg = msg.map(|body| body.to_uppercase());
assert_eq!(mapped_msg.body(), "HELLO!");
Sourcepub fn try_map<U, E, F: Fn(&Body) -> Result<U, E>>(
&self,
f: F,
) -> Result<ChatMessage<U>, E>
pub fn try_map<U, E, F: Fn(&Body) -> Result<U, E>>( &self, f: F, ) -> Result<ChatMessage<U>, E>
Applies a fallible function f
to the body of the chat message and returns a new chat message
with the mapped body or an error if the function fails.
§Arguments
f
- The fallible function to apply to the message body.
Trait Implementations§
Source§impl<Body: Clone> Clone for ChatMessage<Body>
impl<Body: Clone> Clone for ChatMessage<Body>
Source§fn clone(&self) -> ChatMessage<Body>
fn clone(&self) -> ChatMessage<Body>
Returns a copy 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<Body: Debug> Debug for ChatMessage<Body>
impl<Body: Debug> Debug for ChatMessage<Body>
Source§impl<'de, Body> Deserialize<'de> for ChatMessage<Body>where
Body: Deserialize<'de>,
impl<'de, Body> Deserialize<'de> for ChatMessage<Body>where
Body: Deserialize<'de>,
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<T: Display> Display for ChatMessage<T>
impl<T: Display> Display for ChatMessage<T>
Source§impl<T> From<ChatMessage<T>> for Data<T>
impl<T> From<ChatMessage<T>> for Data<T>
Source§fn from(chat: ChatMessage<T>) -> Self
fn from(chat: ChatMessage<T>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<Body> Freeze for ChatMessage<Body>where
Body: Freeze,
impl<Body> RefUnwindSafe for ChatMessage<Body>where
Body: RefUnwindSafe,
impl<Body> Send for ChatMessage<Body>where
Body: Send,
impl<Body> Sync for ChatMessage<Body>where
Body: Sync,
impl<Body> Unpin for ChatMessage<Body>where
Body: Unpin,
impl<Body> UnwindSafe for ChatMessage<Body>where
Body: UnwindSafe,
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