use crate::message::{Media, Message, Part, Role};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Prompt {
parts: Vec<Part>,
}
impl Prompt {
pub fn new() -> Self {
Self::default()
}
pub fn text(text: impl Into<String>) -> Self {
Self::new().with_text(text)
}
pub fn with_text(mut self, text: impl Into<String>) -> Self {
self.parts.push(Part::Text(text.into()));
self
}
pub fn with_media(mut self, media: Media) -> Self {
self.parts.push(Part::Media(media));
self
}
pub fn with_image_url(self, url: impl Into<String>) -> Self {
self.with_media(Media::image_url(url))
}
pub fn with_image_bytes(
self,
content_type: impl Into<String>,
bytes: impl AsRef<[u8]>,
) -> Self {
self.with_media(Media::from_bytes(content_type, bytes))
}
pub fn parts(&self) -> &[Part] {
&self.parts
}
pub(crate) fn into_message(self) -> Message {
Message::new(Role::User, self.parts)
}
}
pub trait IntoPrompt {
fn into_prompt(self) -> Prompt;
}
impl<T: Into<String>> IntoPrompt for T {
fn into_prompt(self) -> Prompt {
Prompt::text(self)
}
}
impl IntoPrompt for Prompt {
fn into_prompt(self) -> Prompt {
self
}
}
impl IntoPrompt for Media {
fn into_prompt(self) -> Prompt {
Prompt::new().with_media(self)
}
}