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

Code before:
			mediaType := fmt.Sprintf("application/vnd.ollama.image.%s", c.Name)
			_, layers = removeLayerFromLayers(layers, mediaType)

			layer, err := CreateLayer(strings.NewReader(c.Args))
			if err != nil {
				return err
			}

			layer.MediaType = mediaType
			layers = append(layers, layer)
		default:
			// runtime parameters, build a list of args for each parameter to allow multiple values to be specified (ex: multiple stop sequences)
			params[c.Name] = append(params[c.Name], c.Args)
		}
	}

	// Create a single layer for the parameters
	if len(params) > 0 {
		fn(api.ProgressResponse{Status: "creating parameter layer"})

		formattedParams, err := formatParams(params)
		if err != nil {
			return fmt.Errorf("couldn't create params json: %v", err)
		}

		paramsLayer, newLayers := removeLayerFromLayers(layers, "application/vnd.ollama.image.params")
		if paramsLayer != nil {
			paramsBlobPath, err := GetBlobsPath(paramsLayer.Digest)
			if err != nil {
				return err
			}

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

			var inherited map[string]any
			if err := json.NewDecoder(paramsBlob).Decode(&inherited); err != nil {
				return err
			}

			for k, v := range inherited {
				if _, ok := formattedParams[k]; !ok {
					formattedParams[k] = v
				}
			}
		}

		bts, err := json.Marshal(formattedParams)

Review comment (suggestion):
Looks like this is reading the params layer from the current modelfile rather than the parent?

I tried this with a modelfile that doesn't set any parameters and it didnt get any parameters set from the parent since `len(params) == 0`

Code after:
			}
			l.MediaType = "application/vnd.ollama.image.adapter"
			layers = append(layers, l)
		case "license":
			fn(api.ProgressResponse{Status: fmt.Sprintf("creating model %s layer", c.Name)})
			mediaType := fmt.Sprintf("application/vnd.ollama.image.%s", c.Name)

			layer, err := CreateLayer(strings.NewReader(c.Args))
			if err != nil {
				return err
			}

			layer.MediaType = mediaType
			layers = append(layers, layer)
		case "template", "system", "prompt":
			fn(api.ProgressResponse{Status: fmt.Sprintf("creating model %s layer", c.Name)})
			// remove the layer if one exists
			mediaType := fmt.Sprintf("application/vnd.ollama.image.%s", c.Name)
			layers = removeLayerFromLayers(layers, mediaType)

			layer, err := CreateLayer(strings.NewReader(c.Args))
			if err != nil {
				return err
			}

			layer.MediaType = mediaType
			layers = append(layers, layer)
		default:
			// runtime parameters, build a list of args for each parameter to allow multiple values to be specified (ex: multiple stop sequences)
			params[c.Name] = append(params[c.Name], c.Args)
		}
	}

	// Create a single layer for the parameters
	if len(params) > 0 {
		fn(api.ProgressResponse{Status: "creating parameter layer"})

		layers = removeLayerFromLayers(layers, "application/vnd.ollama.image.params")
		formattedParams, err := formatParams(params)
		if err != nil {
			return fmt.Errorf("couldn't create params json: %v", err)
		}

		for k, v := range sourceParams {
			if _, ok := formattedParams[k]; !ok {
				formattedParams[k] = v
			}
		}

		bts, err := json.Marshal(formattedParams)
		if err != nil {