pub struct Message {
pub role: Role,
pub content: String,
}Expand description
A single message in the conversation history.
Fields§
§role: RoleThe role of the speaker who produced this message.
content: StringThe textual content of the message.
Implementations§
Source§impl Message
impl Message
Sourcepub fn is_assistant(&self) -> bool
pub fn is_assistant(&self) -> bool
Return true if this is an Assistant role message.
Sourcepub fn word_count(&self) -> usize
pub fn word_count(&self) -> usize
Return the approximate number of whitespace-separated words in the content.
Sourcepub fn byte_len(&self) -> usize
pub fn byte_len(&self) -> usize
Return the byte length of the content string.
For ASCII-only content this equals the character count; for multi-byte UTF-8 sequences it will be larger. Useful for rough token estimation.
Sourcepub fn content_starts_with(&self, prefix: &str) -> bool
pub fn content_starts_with(&self, prefix: &str) -> bool
Return true if the content string starts with prefix.
The check is byte-exact (case-sensitive). Returns true for an empty
prefix regardless of content.
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>,
Deserialize this value from the given Serde deserializer. Read more
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