pub struct Prompt {
pub messages: Vec<Message>,
}Expand description
A collection of messages forming a prompt.
Prompt implements From<&str>, From<String>, From<Message>, and
From<Vec<Message>>, so most call sites can pass their input directly to
RequestBuilder::prompt.
§Examples
use rai_sdk::{Message, Prompt};
let prompt = Prompt::single(Message::system("Be brief."))
.with_message(Message::user("Define entropy."));
assert_eq!(prompt.system_message(), Some("Be brief."));
assert_eq!(prompt.conversation_messages().len(), 1);Fields§
§messages: Vec<Message>Messages in provider order; system messages usually come first.
Implementations§
Source§impl Prompt
impl Prompt
Sourcepub fn push_message(&mut self, message: Message)
pub fn push_message(&mut self, message: Message)
Append a message to the prompt.
Sourcepub fn with_message(self, message: Message) -> Self
pub fn with_message(self, message: Message) -> Self
Return a new prompt with an additional message appended.
Sourcepub fn with_history(self, history: Vec<ConversationTurn>) -> Self
pub fn with_history(self, history: Vec<ConversationTurn>) -> Self
Add a history of conversation turns to the prompt.
Sourcepub fn push_turn(&mut self, turn: ConversationTurn)
pub fn push_turn(&mut self, turn: ConversationTurn)
Append a single conversation turn to the prompt.
Sourcepub fn system_message(&self) -> Option<&str>
pub fn system_message(&self) -> Option<&str>
Extract the system message if present (first system message).
Sourcepub fn conversation_messages(&self) -> Vec<&Message>
pub fn conversation_messages(&self) -> Vec<&Message>
Get non-system messages.
Sourcepub fn is_multimodal(&self) -> bool
pub fn is_multimodal(&self) -> bool
Check if this prompt contains any multimodal content.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Prompt
impl<'de> Deserialize<'de> for Prompt
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
impl StructuralPartialEq for Prompt
Auto Trait Implementations§
impl Freeze for Prompt
impl RefUnwindSafe for Prompt
impl Send for Prompt
impl Sync for Prompt
impl Unpin for Prompt
impl UnsafeUnpin for Prompt
impl UnwindSafe for Prompt
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