Implementation:Ollama Ollama XCreate Client
| Knowledge Sources | |
|---|---|
| Domains | Model Creation, Safetensors |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Provides client-side model creation for importing safetensors-based models (both LLM and image generation) directly to disk, bypassing the HTTP API.
Description
CreateModel detects whether a directory contains a safetensors LLM model (config.json + .safetensors) or image generation model (model_index.json), then delegates to the appropriate creation function. Creates blob layers on disk via manifest.NewLayer, supports optional quantization (int4, int8, nvfp4, mxfp8) through callback-based architecture to avoid import cycles. Writes manifests with model capabilities, parser/renderer names, and Modelfile configurations (template, system prompt, license).
Usage
Called by ollama create when importing models from local directories in the experimental safetensors format.
Code Reference
Source Location
- Repository: Ollama
- File: x/create/client/create.go
- Lines: 1-480
Signature
type ModelfileConfig struct {
Template string
System string
License string
}
type CreateOptions struct {
ModelName string
ModelDir string
Quantize string
Modelfile *ModelfileConfig
}
func CreateModel(opts CreateOptions, p *progress.Progress) error
Import
import "github.com/ollama/ollama/x/create/client"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| opts | CreateOptions | Yes | Model name, directory path, quantization type, and Modelfile config |
| p | *progress.Progress | Yes | Progress reporter for UI feedback |
Outputs
| Name | Type | Description |
|---|---|---|
| error | error | Non-nil if model creation fails |
Usage Examples
p := progress.NewProgress(os.Stderr)
err := client.CreateModel(client.CreateOptions{
ModelName: "my-model:latest",
ModelDir: "/path/to/model",
Quantize: "int4",
Modelfile: &client.ModelfileConfig{
Template: "chatml",
System: "You are a helpful assistant.",
},
}, p)