Skip to main content

MtmdContext

Struct MtmdContext 

Source
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

Source

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

Returns an MtmdInitError variant matching the wrapper’s status code.

Source

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.

Source

pub fn decode_use_mrope(&self) -> bool

Check whether the current model uses M-RoPE for llama_decode.

Source

pub fn support_vision(&self) -> bool

Check whether the current model supports vision input.

Source

pub fn support_audio(&self) -> bool

Check whether the current model supports audio input.

Source

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.

Source

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

Returns an MtmdTokenizeError variant matching the wrapper’s status code.

Source

pub fn encode_chunk( &self, chunk: &MtmdInputChunk, ) -> Result<(), MtmdEncodeError>

Encode a chunk for image/audio processing.

§Errors

Returns an MtmdEncodeError variant matching the wrapper’s status code.

Trait Implementations§

Source§

impl Debug for MtmdContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MtmdContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for MtmdContext

Source§

impl Sync for MtmdContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.