@@ -340,15 +340,17 @@ fn create_modelfile(commands: Vec<(&str, Output)>) -> Result<Modelfile, String>
340340 for command in commands {
341341 let _ = match ( command. 0 . to_lowercase ( ) . as_str ( ) , command. 1 ) {
342342 //TODO: Can add validations for path if its a gguf file later
343- ( "from" , Output :: Single ( from) ) => modelfile. add_from ( from) ,
343+ ( "from" , Output :: Single ( from) ) => modelfile. add_from ( from. trim ( ) ) ,
344344 ( "parameter" , Output :: Pair ( ( param, argument) ) ) => {
345- modelfile. add_parameter ( param, argument)
345+ modelfile. add_parameter ( param, argument. trim ( ) )
346346 }
347- ( "template" , Output :: Single ( template) ) => modelfile. add_template ( template) ,
348- ( "system" , Output :: Single ( system) ) => modelfile. add_system ( system) ,
349- ( "adapter" , Output :: Single ( adapter) ) => modelfile. add_adapter ( adapter) ,
350- ( "message" , Output :: Pair ( ( role, message) ) ) => modelfile. add_message ( role, message) ,
351- ( "license" , Output :: Single ( license) ) => modelfile. add_license ( license) ,
347+ ( "template" , Output :: Single ( template) ) => modelfile. add_template ( template. trim ( ) ) ,
348+ ( "system" , Output :: Single ( system) ) => modelfile. add_system ( system. trim ( ) ) ,
349+ ( "adapter" , Output :: Single ( adapter) ) => modelfile. add_adapter ( adapter. trim ( ) ) ,
350+ ( "message" , Output :: Pair ( ( role, message) ) ) => {
351+ modelfile. add_message ( role, message. trim ( ) )
352+ }
353+ ( "license" , Output :: Single ( license) ) => modelfile. add_license ( license. trim ( ) ) ,
352354 ( "#" , comment) => {
353355 let comment_str = comment. to_string ( ) ;
354356 modelfile. add_comment ( & comment_str)
@@ -546,4 +548,15 @@ mod tests {
546548 // modelfile has more than 2 FROM
547549 assert ! ( parse_from_file( "fixtures/llama_bad.Modelfile" ) . is_err( ) )
548550 }
551+
552+ #[ test]
553+ fn test_values_should_be_trimmed ( ) -> Result < ( ) , String > {
554+ let modelfile_content = "
555+ FROM llama3.2
556+ PARAMETER num_ctx 4096
557+ " ;
558+ let modelfile = parse ( modelfile_content) ?;
559+ assert_eq ! ( modelfile. from. unwrap( ) , String :: from( "llama3.2" ) ) ;
560+ Ok ( ( ) )
561+ }
549562}
0 commit comments