pub struct MtmdContext { /* private fields */ }Expand description
Context for assembling multimodal turns. Holds the chat template
and (eventually) the tokenizer; per-family runners hand the
resulting AssembledTurn into their prefill path.
Implementations§
Source§impl MtmdContext
impl MtmdContext
Sourcepub fn from_template_source(src: impl Into<String>) -> Self
pub fn from_template_source(src: impl Into<String>) -> Self
Build a context from a Jinja chat template (typically loaded
from a GGUF via crate::ChatTemplate::from_gguf).
pub fn with_tokens(self, bos: Option<String>, eos: Option<String>) -> Self
pub fn template_source(&self) -> &str
pub fn bos_token(&self) -> Option<&str>
pub fn eos_token(&self) -> Option<&str>
Sourcepub fn build_turn(
&self,
turns: &[MtmdTurn],
tokenizer_fn: Option<&(dyn Fn(&str) -> Result<Vec<u32>> + '_)>,
) -> Result<AssembledTurn>
pub fn build_turn( &self, turns: &[MtmdTurn], tokenizer_fn: Option<&(dyn Fn(&str) -> Result<Vec<u32>> + '_)>, ) -> Result<AssembledTurn>
Assemble one turn list into AssembledTurn.
Renders the text using the registered chat template, replaces
each <|image|> / <|audio|> marker with the per-family
placeholder token id (resolved from the optional tokenizer
vocabulary), and records the order of media in image_refs /
audio_refs so the runner can insert the corresponding
embeddings at decode time.
tokenizer_fn lets the caller plug in a per-family text→ids
encoder (typically auto_tokenize). Passing None populates
text_tokens with an empty vec — useful for callers that
own tokenization separately.
Auto Trait Implementations§
impl Freeze for MtmdContext
impl RefUnwindSafe for MtmdContext
impl Send for MtmdContext
impl Sync 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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