pub struct MtmdContext {
pub context: NonNull<mtmd_context>,
}Expand description
Safe wrapper around mtmd_context.
This represents an initialized multimodal context that can process text, images, and audio through llama.cpp’s multimodal interface.
Fields§
§context: NonNull<mtmd_context>Raw pointer to the underlying mtmd_context.
Implementations§
Source§impl MtmdContext
impl MtmdContext
Sourcepub fn init_from_file(
mmproj_path: &str,
text_model: &LlamaModel,
params: &MtmdContextParams,
) -> Result<Self, MtmdInitError>
pub fn init_from_file( mmproj_path: &str, text_model: &LlamaModel, params: &MtmdContextParams, ) -> Result<Self, MtmdInitError>
Initialize MTMD context from a multimodal projection file.
§Errors
This function will return an error if:
- The path cannot be converted to a C string
- The underlying C function returns null (indicating initialization failure)
Sourcepub fn decode_use_non_causal(&self, chunk: &MtmdInputChunk) -> bool
pub fn decode_use_non_causal(&self, chunk: &MtmdInputChunk) -> bool
Check whether non-causal attention mask is needed before llama_decode
for the given input chunk.
Sourcepub fn decode_use_mrope(&self) -> bool
pub fn decode_use_mrope(&self) -> bool
Check whether the current model uses M-RoPE for llama_decode.
Sourcepub fn support_vision(&self) -> bool
pub fn support_vision(&self) -> bool
Check whether the current model supports vision input.
Sourcepub fn support_audio(&self) -> bool
pub fn support_audio(&self) -> bool
Check whether the current model supports audio input.
Sourcepub fn get_audio_sample_rate(&self) -> Option<u32>
pub fn get_audio_sample_rate(&self) -> Option<u32>
Get audio sample rate in Hz (e.g., 16000 for Whisper). Returns None if audio is not supported.
Sourcepub fn tokenize(
&self,
text: MtmdInputText,
bitmaps: &[&MtmdBitmap],
) -> Result<MtmdInputChunks, MtmdTokenizeError>
pub fn tokenize( &self, text: MtmdInputText, bitmaps: &[&MtmdBitmap], ) -> Result<MtmdInputChunks, MtmdTokenizeError>
Tokenize input text and bitmaps into chunks.
The input text must contain media markers (default: <__media__>) that will be
replaced with the corresponding bitmap data from the bitmaps array.
The number of bitmaps must equal the number of markers in the text.
§Errors
BitmapCountMismatch- Number of bitmaps doesn’t match number of markersImagePreprocessingError- Error occurred during image preprocessingUnknownError- Other tokenization error occurred
§Example
let text = MtmdInputText {
text: "Here is an image: <__media__>\nDescribe it.".to_string(),
add_special: true,
parse_special: true,
};
let chunks = ctx.tokenize(text, &[bitmap])?;Sourcepub fn encode_chunk(
&self,
chunk: &MtmdInputChunk,
) -> Result<(), MtmdEncodeError>
pub fn encode_chunk( &self, chunk: &MtmdInputChunk, ) -> Result<(), MtmdEncodeError>
Encode a chunk for image/audio processing.
§Errors
Returns MtmdEncodeError::EncodeFailure if encoding fails.
Trait Implementations§
Source§impl Debug for MtmdContext
impl Debug for MtmdContext
Source§impl Drop for MtmdContext
impl Drop for MtmdContext
impl Send for MtmdContext
impl Sync for MtmdContext
Auto Trait Implementations§
impl Freeze for MtmdContext
impl RefUnwindSafe for MtmdContext
impl Unpin for MtmdContext
impl UnsafeUnpin for MtmdContext
impl UnwindSafe for MtmdContext
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more