@@ -26,7 +26,7 @@ pub struct LlamaModel {
2626}
2727
2828/// A Safe wrapper around `llama_chat_message`
29- #[ derive( Debug ) ]
29+ #[ derive( Debug , Eq , PartialEq , Clone ) ]
3030pub struct LlamaChatMessage {
3131 role : CString ,
3232 content : CString ,
@@ -408,6 +408,8 @@ impl LlamaModel {
408408 /// Apply the models chat template to some messages.
409409 /// See https://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template
410410 ///
411+ /// `tmpl` of None means to use the default template provided by llama.cpp for the model
412+ ///
411413 /// # Errors
412414 /// There are many ways this can fail. See [`ApplyChatTemplateError`] for more information.
413415 #[ tracing:: instrument( skip_all) ]
@@ -431,7 +433,7 @@ impl LlamaModel {
431433 } )
432434 . collect ( ) ;
433435 // Set the tmpl pointer
434- let tmpl = tmpl. map ( |v| CString :: new ( v ) ) ;
436+ let tmpl = tmpl. map ( CString :: new) ;
435437 let tmpl_ptr = match tmpl {
436438 Some ( str) => str?. as_ptr ( ) ,
437439 None => std:: ptr:: null ( ) ,
@@ -446,13 +448,14 @@ impl LlamaModel {
446448 buff. as_mut_ptr ( ) ,
447449 buff. len ( ) as i32 ,
448450 ) ;
449- // This should never happen
451+ // A buffer twice the size should be sufficient for all models, if this is not the case for a new model, we can increase it
452+ // The error message informs the user to contact a maintainer
450453 if res > buff. len ( ) as i32 {
451454 return Err ( ApplyChatTemplateError :: BuffSizeError ) ;
452455 }
453456 String :: from_utf8 ( buff. iter ( ) . filter ( |c| * * c > 0 ) . map ( |& c| c as u8 ) . collect ( ) )
454- } ;
455- Ok ( formatted_chat? )
457+ } ? ;
458+ Ok ( formatted_chat)
456459 }
457460}
458461
0 commit comments