pub struct MtmdInputText<'a> { /* private fields */ }Expand description
Text input for MtmdContext::tokenize.
The prompt string must contain the media marker (see
MtmdContext::default_marker) once for every bitmap to be embedded.
The prompt is passed to llama.cpp as an explicit pointer + length
(mtmd_input_text::text_len), so interior NUL bytes are preserved rather
than truncating the prompt — use MtmdInputText::from_bytes when the
prompt is not guaranteed NUL-free.
Implementations§
Source§impl<'a> MtmdInputText<'a>
impl<'a> MtmdInputText<'a>
Sourcepub fn new(text: &'a str, add_special: bool, parse_special: bool) -> Self
pub fn new(text: &'a str, add_special: bool, parse_special: bool) -> Self
Create a new MtmdInputText from a string prompt.
text– the prompt (interior NUL bytes are permitted and preserved)add_special– whether to add BOS/EOS tokensparse_special– whether to parse special tokens embedded in the text
Sourcepub fn from_bytes(
text: &'a [u8],
add_special: bool,
parse_special: bool,
) -> Self
pub fn from_bytes( text: &'a [u8], add_special: bool, parse_special: bool, ) -> Self
Create a new MtmdInputText from raw prompt bytes.
Unlike a C string, the prompt length is carried explicitly, so text
may contain interior NUL bytes without truncating the prompt. The bytes
are copied into an owned, NUL-terminated buffer.
text– the prompt bytes (typically UTF-8)add_special– whether to add BOS/EOS tokensparse_special– whether to parse special tokens embedded in the text
Sourcepub fn try_new(
text: &'a str,
add_special: bool,
parse_special: bool,
) -> Result<Self, NulError>
pub fn try_new( text: &'a str, add_special: bool, parse_special: bool, ) -> Result<Self, NulError>
Try to create a new MtmdInputText from a string prompt.
Retained for backwards compatibility. Interior NUL bytes are now
permitted (see MtmdInputText::new), so this never returns Err;
prefer new.
§Errors
Never returns an error; the Result is kept for API stability.