@@ -50,6 +50,14 @@ enum Output<'a> {
5050 Single ( & ' a str ) ,
5151 Pair ( ( & ' a str , & ' a str ) ) ,
5252}
53+ impl < ' a > Display for Output < ' a > {
54+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
55+ match self {
56+ Self :: Single ( word) => write ! ( f, "{}" , word) ,
57+ Self :: Pair ( ( word, word_1) ) => write ! ( f, "{} {}" , word, word_1) ,
58+ }
59+ }
60+ }
5361
5462impl FromStr for Role {
5563 type Err = String ;
@@ -341,9 +349,15 @@ fn create_modelfile(commands: Vec<(&str, Output)>) -> Result<Modelfile, String>
341349 ( "adapter" , Output :: Single ( adapter) ) => modelfile. add_adapter ( adapter) ,
342350 ( "message" , Output :: Pair ( ( role, message) ) ) => modelfile. add_message ( role, message) ,
343351 ( "license" , Output :: Single ( license) ) => modelfile. add_license ( license) ,
344- ( "#" , Output :: Single ( comment) ) => modelfile. add_comment ( comment) ,
345- _ => {
346- modelfile. errors . push ( String :: from ( "Invalid instruction" ) ) ;
352+ ( "#" , comment) => {
353+ let comment_str = comment. to_string ( ) ;
354+ modelfile. add_comment ( & comment_str)
355+ }
356+ ( instruction, command) => {
357+ modelfile. errors . push ( format ! (
358+ "Invalid instruction Instruction: `{}` command: `{}`" ,
359+ instruction, command
360+ ) ) ;
347361 Ok ( ( ) )
348362 }
349363 } ;
@@ -437,6 +451,25 @@ mod tests {
437451
438452 assert ! ( parse( modelfile) . is_ok( ) ) ;
439453 }
454+ #[ test]
455+ fn test_invalid_instruction ( ) {
456+ let modelfile = "
457+ FROM llama3.2
458+ adapter num_ctx 4096
459+ " ;
460+
461+ assert ! ( parse( modelfile) . is_err( ) ) ;
462+ }
463+
464+ #[ test]
465+ fn test_valid_comment ( ) {
466+ let modelfile = "
467+ FROM llama3.2
468+ # system num_ctx 4096
469+ " ;
470+
471+ assert ! ( parse( modelfile) . is_ok( ) ) ;
472+ }
440473
441474 #[ test]
442475 fn test_parse_modelfile_without_from ( ) {
0 commit comments