#[non_exhaustive]pub struct File {
pub media_type: String,
pub source: MediaSource,
pub filename: Option<String>,
pub provider_data: ProviderData,
}Expand description
File input: a document (PDF, plain text, …), audio, or video.
What a provider takes depends on the media type:
ChatCapability::FileInput covers
documents, AudioInput an
audio/* file and VideoInput a
video/* one.
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.media_type: StringIANA media type, e.g. application/pdf.
source: MediaSourceFile data or location.
filename: Option<String>Optional file name shown to the model.
provider_data: ProviderDataProvider-specific data.
Implementations§
Source§impl File
impl File
Sourcepub fn base64(
media_type: impl Into<String>,
data: impl Into<Base64Data>,
) -> Self
pub fn base64( media_type: impl Into<String>, data: impl Into<Base64Data>, ) -> Self
File from inline base64 data.
Sourcepub fn bytes(media_type: impl Into<String>, data: impl AsRef<[u8]>) -> Self
pub fn bytes(media_type: impl Into<String>, data: impl AsRef<[u8]>) -> Self
File from raw bytes, sent inline; see MediaSource::bytes.
Sourcepub fn provider_file(
media_type: impl Into<String>,
origin: impl Into<String>,
id: impl Into<String>,
) -> Self
pub fn provider_file( media_type: impl Into<String>, origin: impl Into<String>, id: impl Into<String>, ) -> Self
File stored by a provider; see MediaSource::provider_file.
use allama::File;
let file = File::provider_file("application/pdf", "anthropic", "file_011CNha8iCJcU1wXNR6q4V8w");
assert_eq!(file.source.provider_file_id().map(|(origin, _)| origin), Some("anthropic"));Sourcepub fn new(media_type: impl Into<String>, source: MediaSource) -> Self
pub fn new(media_type: impl Into<String>, source: MediaSource) -> Self
File from any source.
Sourcepub fn with_filename(self, filename: impl Into<String>) -> Self
pub fn with_filename(self, filename: impl Into<String>) -> Self
Set the file name.
Sourcepub fn with_provider_data(self, provider_data: ProviderData) -> Self
pub fn with_provider_data(self, provider_data: ProviderData) -> Self
Attach provider data.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for File
impl<'de> Deserialize<'de> for File
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 Eq for File
Source§impl From<File> for ContentPart
impl From<File> for ContentPart
impl StructuralPartialEq for File
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
impl UnwindSafe for File
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