pub struct ContentBuilder { /* private fields */ }Expand description
Fluent builder for composing a multimodal Message from interleaved
text, image, file, and audio parts.
use openrouter::{ContentBuilder, ImageDetail, Role};
let msg = ContentBuilder::new()
.add_text("Compare these:")
.add_image("https://example.com/a.png")
.add_image_with_detail("https://example.com/b.png", ImageDetail::High)
.build_message(Role::User);
assert_eq!(msg.role, Role::User);Implementations§
Source§impl ContentBuilder
impl ContentBuilder
Sourcepub fn add_image_with_detail(
self,
url: impl Into<String>,
detail: ImageDetail,
) -> Self
pub fn add_image_with_detail( self, url: impl Into<String>, detail: ImageDetail, ) -> Self
Append an image-URL part with an explicit detail level.
Sourcepub fn add_base64_image(self, path: impl AsRef<Path>) -> Result<Self>
pub fn add_base64_image(self, path: impl AsRef<Path>) -> Result<Self>
Read an image from disk, base64-encode it, and append it.
Sourcepub fn add_pdf(
self,
url: impl Into<String>,
filename: impl Into<String>,
) -> Self
pub fn add_pdf( self, url: impl Into<String>, filename: impl Into<String>, ) -> Self
Append a PDF reference by URL.
Sourcepub fn add_base64_pdf(
self,
path: impl AsRef<Path>,
filename: impl Into<String>,
) -> Result<Self>
pub fn add_base64_pdf( self, path: impl AsRef<Path>, filename: impl Into<String>, ) -> Result<Self>
Read a PDF from disk, base64-encode it, and append it.
Sourcepub fn add_audio(self, path: impl AsRef<Path>) -> Result<Self>
pub fn add_audio(self, path: impl AsRef<Path>) -> Result<Self>
Read an audio file from disk and append it.
Sourcepub fn add_text_file(self, path: impl AsRef<Path>) -> Result<Self>
pub fn add_text_file(self, path: impl AsRef<Path>) -> Result<Self>
Read a UTF-8 text file and append its contents as a text part.
Sourcepub fn add_part(self, part: ContentPart) -> Self
pub fn add_part(self, part: ContentPart) -> Self
Append an arbitrary pre-built part (escape hatch).
Sourcepub fn build_message(self, role: Role) -> Message
pub fn build_message(self, role: Role) -> Message
Finalize as a Message with the given role.
Sourcepub fn build_parts(self) -> Vec<ContentPart>
pub fn build_parts(self) -> Vec<ContentPart>
Finalize as a raw Vec<ContentPart>.
Trait Implementations§
Source§impl Clone for ContentBuilder
impl Clone for ContentBuilder
Source§fn clone(&self) -> ContentBuilder
fn clone(&self) -> ContentBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContentBuilder
impl Debug for ContentBuilder
Source§impl Default for ContentBuilder
impl Default for ContentBuilder
Source§fn default() -> ContentBuilder
fn default() -> ContentBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ContentBuilder
impl RefUnwindSafe for ContentBuilder
impl Send for ContentBuilder
impl Sync for ContentBuilder
impl Unpin for ContentBuilder
impl UnsafeUnpin for ContentBuilder
impl UnwindSafe for ContentBuilder
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