#[non_exhaustive]pub struct Media {
pub content_type: String,
pub source: MediaSource,
pub name: Option<String>,
}Expand description
An image, audio or other file in a message.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.content_type: StringMIME type, for example image/png.
source: MediaSourceWhere the bytes are.
name: Option<String>File name, if known.
Implementations§
Source§impl Media
impl Media
Sourcepub fn new(content_type: impl Into<String>, source: MediaSource) -> Self
pub fn new(content_type: impl Into<String>, source: MediaSource) -> Self
Creates media from its MIME type and source.
Sourcepub fn from_url(content_type: impl Into<String>, url: impl Into<String>) -> Self
pub fn from_url(content_type: impl Into<String>, url: impl Into<String>) -> Self
Creates media the provider downloads from url. Not every provider accepts URLs; use
Media::from_bytes when yours does not.
Sourcepub fn image_url(url: impl Into<String>) -> Self
pub fn image_url(url: impl Into<String>) -> Self
Creates an image the provider downloads from url. The MIME type is guessed from the
file extension (png, jpg, jpeg, gif, webp); other URLs are sent as
image/jpeg. Use Media::from_url to set it yourself.
Sourcepub fn from_bytes(
content_type: impl Into<String>,
bytes: impl AsRef<[u8]>,
) -> Self
pub fn from_bytes( content_type: impl Into<String>, bytes: impl AsRef<[u8]>, ) -> Self
Creates media from its bytes, for example an image read from a file. The bytes are sent base64 encoded inside the request.
Sourcepub fn from_base64(
content_type: impl Into<String>,
data: impl Into<String>,
) -> Self
pub fn from_base64( content_type: impl Into<String>, data: impl Into<String>, ) -> Self
Creates media from bytes that are already base64 encoded.
Sourcepub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Sets the file name. Some providers show it to the model.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Media
impl<'de> Deserialize<'de> for Media
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 From<Media> for ToolOutput
impl From<Media> for ToolOutput
Source§impl IntoPrompt for Media
impl IntoPrompt for Media
Source§fn into_prompt(self) -> Prompt
fn into_prompt(self) -> Prompt
Converts the value into a prompt.
impl StructuralPartialEq for Media
Auto Trait Implementations§
impl Forget for Media
impl Freeze for Media
impl RefUnwindSafe for Media
impl Send for Media
impl Sync for Media
impl Unpin for Media
impl UnsafeUnpin for Media
impl UnwindSafe for Media
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