pub struct ImageData {
pub media_type: String,
pub data: Vec<u8>,
}Expand description
Helper structure for handling image data in prompts.
This struct provides a convenient way to represent images that can be included in multimodal prompts.
Fields§
§media_type: StringThe MIME media type (e.g., “image/jpeg”, “image/png”).
data: Vec<u8>The raw image data.
Implementations§
Source§impl ImageData
impl ImageData
Sourcepub fn new(media_type: impl Into<String>, data: Vec<u8>) -> Self
pub fn new(media_type: impl Into<String>, data: Vec<u8>) -> Self
Creates a new ImageData instance with the given media type and data.
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self>
Creates an ImageData instance from a file path.
The media type is inferred from the file extension.
§Errors
Returns an error if the file cannot be read or if the media type cannot be determined from the file extension.
Sourcepub fn from_base64(
base64_str: &str,
media_type: impl Into<String>,
) -> Result<Self, DecodeError>
pub fn from_base64( base64_str: &str, media_type: impl Into<String>, ) -> Result<Self, DecodeError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ImageData
impl<'de> Deserialize<'de> for ImageData
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
Source§impl ToPrompt for ImageData
impl ToPrompt for ImageData
Source§fn to_prompt_parts(&self) -> Vec<PromptPart>
fn to_prompt_parts(&self) -> Vec<PromptPart>
Converts the object into a vector of
PromptParts using the default “full” mode. Read moreSource§fn to_prompt_parts_with_mode(&self, mode: &str) -> Vec<PromptPart>
fn to_prompt_parts_with_mode(&self, mode: &str) -> Vec<PromptPart>
Converts the object into a vector of
PromptParts based on a mode. Read moreSource§fn to_prompt_with_mode(&self, mode: &str) -> String
fn to_prompt_with_mode(&self, mode: &str) -> String
Converts the object into a prompt string based on a mode. Read more
Source§fn to_prompt(&self) -> String
fn to_prompt(&self) -> String
Converts the object into a prompt string using the default “full” mode. Read more
Source§fn prompt_schema() -> String
fn prompt_schema() -> String
Returns a schema-level prompt for the type itself. Read more
Auto Trait Implementations§
impl Freeze for ImageData
impl RefUnwindSafe for ImageData
impl Send for ImageData
impl Sync for ImageData
impl Unpin for ImageData
impl UnwindSafe for ImageData
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