Repository: ollama/ollama
File: server/images.go (Go)

Code before:
				fn(api.ProgressResponse{Status: "reading model metadata"})
				fromConfigPath, err := GetBlobsPath(manifest.Config.Digest)
				if err != nil {
					return err
				}

				fromConfigFile, err := os.Open(fromConfigPath)
				if err != nil {
					return err
				}
				defer fromConfigFile.Close()

				var fromConfig ConfigV2
				if err := json.NewDecoder(fromConfigFile).Decode(&fromConfig); err != nil {
					return err
				}

				// if the model is not in gguf format, pull the base model to try and get it in gguf format
				if fromConfig.ModelFormat != "gguf" {
					fn(api.ProgressResponse{Status: "updating base model"})
					parent, err := GetModel(c.Args)
					if err != nil {
						return err
					}

					switch {
					case parent.OriginalModel != "":
						if err := PullModel(ctx, parent.OriginalModel, &RegistryOptions{}, fn); err != nil {
							log.Printf("error pulling parent model: %v", err)
						}
					default:
						if err := PullModel(ctx, parent.ShortName, &RegistryOptions{}, fn); err != nil {
							log.Printf("error pulling model: %v", err)
						}
					}

					// Reset the file pointer to the beginning of the file
					_, err = fromConfigFile.Seek(0, 0)
					if err != nil {
						return fmt.Errorf("update from config after pull: %w", err)
					}
					if err := json.NewDecoder(fromConfigFile).Decode(&fromConfig); err != nil {
						return err
					}
				}

				// if the model is still not in gguf format, error out
				if fromConfig.ModelFormat != "gguf" {
					return fmt.Errorf("%s is not in gguf format, this base model is not compatible with this version of ollama", c.Args)
				}


Review comment (suggestion):
I think this would be slightly easier to read w/o the full switch statement. Something like:

```
originalModel := parent.OriginalModel
if originalModel == "" {
    originalModel = parent.ShortName
}

if err := PullModel(ctx, originalModel, ...)
```



Code after:
				fn(api.ProgressResponse{Status: "reading model metadata"})
				fromConfigPath, err := GetBlobsPath(manifest.Config.Digest)
				if err != nil {
					return err
				}

				fromConfigFile, err := os.Open(fromConfigPath)
				if err != nil {
					return err
				}
				defer fromConfigFile.Close()

				var fromConfig ConfigV2
				if err := json.NewDecoder(fromConfigFile).Decode(&fromConfig); err != nil {
					return err
				}

				// if the model is not in gguf format, pull the base model to try and get it in gguf format
				if fromConfig.ModelFormat != "gguf" {
					fn(api.ProgressResponse{Status: "updating base model"})
					parent, err := GetModel(c.Args)
					if err != nil {
						return err
					}

					originalModel := parent.OriginalModel
					if originalModel == "" {
						originalModel = parent.ShortName
					}
					if err := PullModel(ctx, originalModel, &RegistryOptions{}, fn); err != nil {
						log.Printf("error pulling parent model: %v", err)
					}

					// Reset the file pointer to the beginning of the file
					_, err = fromConfigFile.Seek(0, 0)
					if err != nil {
						return fmt.Errorf("update from config after pull: %w", err)
					}
					if err := json.NewDecoder(fromConfigFile).Decode(&fromConfig); err != nil {
						return err
					}
				}

				// if the model is still not in gguf format, error out
				if fromConfig.ModelFormat != "gguf" {
					return fmt.Errorf("%s is not in gguf format, this base model is not compatible with this version of ollama", c.Args)
				}

				config.SetModelFormat(fromConfig.ModelFormat)
				config.SetModelFamily(append(fromConfig.ModelFamilies, fromConfig.ModelFamily)...)
				config.SetModelType(fromConfig.ModelType)