@@ -310,14 +310,19 @@ func overwriteModelConfig(mf *modelfile, config *ModelfileGenConfig) {
310310// AutoModelfile creates a new modelfile by the path of the model directory.
311311// It walks the directory and returns the auto-generated modelfile interface.
312312func AutoModelfile (path string , config * ModelfileGenConfig ) (Modelfile , error ) {
313+ // check if the config is nil
314+ if config == nil {
315+ return nil , fmt .Errorf ("config cannot be nil" )
316+ }
317+
313318 mf := & modelfile {
314319 config : hashset .New (),
315320 model : hashset .New (),
316321 code : hashset .New (),
317322 dataset : hashset .New (),
318323 }
319324
320- // Use directory name as model name if config.name is empty
325+ // use directory name as model name if config.name is empty
321326 if config .Name == "" {
322327 mf .name = cleanModelName (filepath .Base (path ))
323328 } else {
@@ -332,7 +337,7 @@ func AutoModelfile(path string, config *ModelfileGenConfig) (Modelfile, error) {
332337
333338 filename := info .Name ()
334339
335- // Skip hidden and skippable files/directories
340+ // skip hidden and skippable files/directories
336341 if isSkippable (filename ) {
337342 if info .IsDir () {
338343 return filepath .SkipDir
@@ -344,7 +349,7 @@ func AutoModelfile(path string, config *ModelfileGenConfig) (Modelfile, error) {
344349 return nil
345350 }
346351
347- // Get relative path from the base directory
352+ // get relative path from the base directory
348353 relPath , err := filepath .Rel (path , fullPath )
349354 if err != nil {
350355 return err
@@ -358,11 +363,11 @@ func AutoModelfile(path string, config *ModelfileGenConfig) (Modelfile, error) {
358363 case isFileType (filename , codeFilePatterns ):
359364 mf .code .Add (relPath )
360365 default :
361- // Skip unrecognized files if IgnoreUnrecognized is true
366+ // skip unrecognized files if IgnoreUnrecognized is true
362367 if config .IgnoreUnrecognized {
363368 return nil
364369 }
365- return fmt .Errorf ("unknown file type: %s" , filename )
370+ return fmt .Errorf ("unknown file type: %s - use --ignore-unrecognized to ignore, and edit the Modelfile manually " , filename )
366371 }
367372
368373 return nil
@@ -372,12 +377,17 @@ func AutoModelfile(path string, config *ModelfileGenConfig) (Modelfile, error) {
372377 return nil , err
373378 }
374379
375- // Get the model config from the config.json file
380+ // check if model files are found
381+ if mf .model .Size () == 0 {
382+ return nil , fmt .Errorf ("no recognized model files found in directory - you may need to edit the Modelfile manually" )
383+ }
384+
385+ // get the model config from the config.json file
376386 if err := parseModelConfig (path , mf ); err != nil {
377387 return nil , err
378388 }
379389
380- // Overwrite the modelfile configurations with the provided config values
390+ // overwrite the modelfile configurations with the provided config values
381391 overwriteModelConfig (mf , config )
382392
383393 return mf , nil
@@ -559,7 +569,7 @@ func (mf *modelfile) SaveToFile(path string) error {
559569 // generate time in the first line
560570 content += fmt .Sprintf ("# Generated at %s\n " , time .Now ().Format (time .RFC3339 ))
561571
562- // Add single value commands
572+ // add single value commands
563573 if mf .name != "" {
564574 content += "\n # Model name\n "
565575 content += fmt .Sprintf ("NAME %s\n " , mf .name )
@@ -589,7 +599,7 @@ func (mf *modelfile) SaveToFile(path string) error {
589599 content += fmt .Sprintf ("QUANTIZATION %s\n " , mf .quantization )
590600 }
591601
592- // Add multi-value commands
602+ // add multi-value commands
593603 content += "\n # Config files (Generated from the files in the model directory)\n "
594604 content += "# Supported file types: " + strings .Join (configFilePatterns , ", " ) + "\n "
595605 configs := mf .GetConfigs ()
@@ -614,6 +624,6 @@ func (mf *modelfile) SaveToFile(path string) error {
614624 content += fmt .Sprintf ("MODEL %s\n " , model )
615625 }
616626
617- // Write to file
627+ // write to file
618628 return os .WriteFile (path , []byte (content ), 0644 )
619629}
0 commit comments