@@ -25,16 +25,18 @@ use crate::token::LlamaToken;
2525/// let audio_chunk = MtmdInputChunkType::Audio;
2626///
2727/// assert_eq!(text_chunk, MtmdInputChunkType::Text);
28+ /// assert_eq!(text_chunk, llama_cpp_sys_2::MTMD_INPUT_CHUNK_TYPE_TEXT.into());
2829/// assert_ne!(text_chunk, image_chunk);
2930/// ```
3031#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
32+ #[ repr( u32 ) ]
3133pub enum MtmdInputChunkType {
3234 /// Text input chunk
33- Text = llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_TEXT as isize ,
35+ Text = llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_TEXT as _ ,
3436 /// Image input chunk
35- Image = llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_IMAGE as isize ,
37+ Image = llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_IMAGE as _ ,
3638 /// Audio input chunk
37- Audio = llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_AUDIO as isize ,
39+ Audio = llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_AUDIO as _ ,
3840}
3941
4042impl From < llama_cpp_sys_2:: mtmd_input_chunk_type > for MtmdInputChunkType {
@@ -43,7 +45,7 @@ impl From<llama_cpp_sys_2::mtmd_input_chunk_type> for MtmdInputChunkType {
4345 llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_TEXT => MtmdInputChunkType :: Text ,
4446 llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_IMAGE => MtmdInputChunkType :: Image ,
4547 llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_AUDIO => MtmdInputChunkType :: Audio ,
46- _ => panic ! ( "Unknown MTMD input chunk type" ) ,
48+ _ => panic ! ( "Unknown MTMD input chunk type: {chunk_type} " ) ,
4749 }
4850 }
4951}
@@ -106,9 +108,7 @@ impl From<llama_cpp_sys_2::mtmd_context_params> for MtmdContextParams {
106108 use_gpu : params. use_gpu ,
107109 print_timings : params. print_timings ,
108110 n_threads : params. n_threads ,
109- media_marker : unsafe { CStr :: from_ptr ( params. media_marker ) }
110- . to_owned ( )
111- . into ( ) ,
111+ media_marker : unsafe { CStr :: from_ptr ( params. media_marker ) } . to_owned ( ) ,
112112 }
113113 }
114114}
@@ -211,10 +211,11 @@ impl MtmdContext {
211211 }
212212
213213 /// Get audio bitrate in Hz (e.g., 16000 for Whisper).
214- /// Returns -1 if audio is not supported.
214+ /// Returns None if audio is not supported.
215215 #[ must_use]
216- pub fn get_audio_bitrate ( & self ) -> i32 {
217- unsafe { llama_cpp_sys_2:: mtmd_get_audio_bitrate ( self . context . as_ptr ( ) ) }
216+ pub fn get_audio_bitrate ( & self ) -> Option < u32 > {
217+ let rate = unsafe { llama_cpp_sys_2:: mtmd_get_audio_bitrate ( self . context . as_ptr ( ) ) } ;
218+ ( rate > 0 ) . then_some ( rate. unsigned_abs ( ) )
218219 }
219220
220221 /// Tokenize input text and bitmaps into chunks.
@@ -275,7 +276,7 @@ impl MtmdContext {
275276 llama_cpp_sys_2:: mtmd_tokenize (
276277 self . context . as_ptr ( ) ,
277278 chunks. chunks . as_ptr ( ) ,
278- & input_text,
279+ & raw const input_text,
279280 bitmap_ptrs. as_ptr ( ) . cast_mut ( ) ,
280281 bitmaps. len ( ) ,
281282 )
@@ -626,15 +627,11 @@ impl MtmdInputChunks {
626627 let chunk_ptr =
627628 unsafe { llama_cpp_sys_2:: mtmd_input_chunks_get ( self . chunks . as_ptr ( ) , index) } ;
628629
629- if chunk_ptr. is_null ( ) {
630- None
631- } else {
632- // Note: We don't own this chunk, it's owned by the chunks collection
633- Some ( MtmdInputChunk {
634- chunk : NonNull :: new ( chunk_ptr. cast_mut ( ) ) . unwrap ( ) ,
635- owned : false ,
636- } )
637- }
630+ // Note: We don't own this chunk, it's owned by the chunks collection
631+ NonNull :: new ( chunk_ptr. cast_mut ( ) ) . map ( |ptr| MtmdInputChunk {
632+ chunk : ptr,
633+ owned : false ,
634+ } )
638635 }
639636
640637 /// Get total number of tokens across all chunks.
@@ -701,7 +698,7 @@ impl MtmdInputChunks {
701698 seq_id,
702699 n_batch,
703700 logits_last,
704- & mut new_n_past,
701+ & raw mut new_n_past,
705702 )
706703 } ;
707704
@@ -753,7 +750,10 @@ impl MtmdInputChunk {
753750
754751 let mut n_tokens = 0usize ;
755752 let tokens_ptr = unsafe {
756- llama_cpp_sys_2:: mtmd_input_chunk_get_tokens_text ( self . chunk . as_ptr ( ) , & mut n_tokens)
753+ llama_cpp_sys_2:: mtmd_input_chunk_get_tokens_text (
754+ self . chunk . as_ptr ( ) ,
755+ & raw mut n_tokens,
756+ )
757757 } ;
758758
759759 if tokens_ptr. is_null ( ) || n_tokens == 0 {
0 commit comments