@@ -25,16 +25,18 @@ use crate::token::LlamaToken;
25
25
/// let audio_chunk = MtmdInputChunkType::Audio;
26
26
///
27
27
/// assert_eq!(text_chunk, MtmdInputChunkType::Text);
28
+ /// assert_eq!(text_chunk, llama_cpp_sys_2::MTMD_INPUT_CHUNK_TYPE_TEXT.into());
28
29
/// assert_ne!(text_chunk, image_chunk);
29
30
/// ```
30
31
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
32
+ #[ repr( u32 ) ]
31
33
pub enum MtmdInputChunkType {
32
34
/// 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 _ ,
34
36
/// 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 _ ,
36
38
/// 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 _ ,
38
40
}
39
41
40
42
impl 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 {
43
45
llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_TEXT => MtmdInputChunkType :: Text ,
44
46
llama_cpp_sys_2:: MTMD_INPUT_CHUNK_TYPE_IMAGE => MtmdInputChunkType :: Image ,
45
47
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} " ) ,
47
49
}
48
50
}
49
51
}
@@ -106,9 +108,7 @@ impl From<llama_cpp_sys_2::mtmd_context_params> for MtmdContextParams {
106
108
use_gpu : params. use_gpu ,
107
109
print_timings : params. print_timings ,
108
110
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 ( ) ,
112
112
}
113
113
}
114
114
}
@@ -211,10 +211,11 @@ impl MtmdContext {
211
211
}
212
212
213
213
/// 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.
215
215
#[ 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 ( ) )
218
219
}
219
220
220
221
/// Tokenize input text and bitmaps into chunks.
@@ -275,7 +276,7 @@ impl MtmdContext {
275
276
llama_cpp_sys_2:: mtmd_tokenize (
276
277
self . context . as_ptr ( ) ,
277
278
chunks. chunks . as_ptr ( ) ,
278
- & input_text,
279
+ & raw const input_text,
279
280
bitmap_ptrs. as_ptr ( ) . cast_mut ( ) ,
280
281
bitmaps. len ( ) ,
281
282
)
@@ -626,15 +627,11 @@ impl MtmdInputChunks {
626
627
let chunk_ptr =
627
628
unsafe { llama_cpp_sys_2:: mtmd_input_chunks_get ( self . chunks . as_ptr ( ) , index) } ;
628
629
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
+ } )
638
635
}
639
636
640
637
/// Get total number of tokens across all chunks.
@@ -701,7 +698,7 @@ impl MtmdInputChunks {
701
698
seq_id,
702
699
n_batch,
703
700
logits_last,
704
- & mut new_n_past,
701
+ & raw mut new_n_past,
705
702
)
706
703
} ;
707
704
@@ -753,7 +750,10 @@ impl MtmdInputChunk {
753
750
754
751
let mut n_tokens = 0usize ;
755
752
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
+ )
757
757
} ;
758
758
759
759
if tokens_ptr. is_null ( ) || n_tokens == 0 {
0 commit comments