pub struct Message {
pub role: Role,
pub content: MessageContent,
pub name: Option<String>,
pub provider_options: Option<MessageProviderOptions>,
}Expand description
A message in a conversation
Fields§
§role: RoleThe role of the message sender
content: MessageContentThe content of the message - can be a string or array of content parts
name: Option<String>Optional name for the message sender
provider_options: Option<MessageProviderOptions>Provider-specific options (e.g., cache control for Anthropic)
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, content: impl Into<MessageContent>) -> Self
pub fn new(role: Role, content: impl Into<MessageContent>) -> Self
Create a new message with text content
Sourcepub fn parts(&self) -> Vec<ContentPart>
pub fn parts(&self) -> Vec<ContentPart>
Get all content parts
Sourcepub fn with_cache_control(self, cache_control: CacheControl) -> Self
pub fn with_cache_control(self, cache_control: CacheControl) -> Self
Add Anthropic cache control to this message
§Example
use stakai::{Message, Role, CacheControl};
let msg = Message::new(Role::System, "System prompt...")
.with_cache_control(CacheControl::ephemeral());Sourcepub fn with_provider_options(self, options: MessageProviderOptions) -> Self
pub fn with_provider_options(self, options: MessageProviderOptions) -> Self
Add provider-specific options to this message
Sourcepub fn cache_control(&self) -> Option<&CacheControl>
pub fn cache_control(&self) -> Option<&CacheControl>
Get the cache control from provider options (if set for Anthropic)
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