Modelfile
A Modelfile is Ollama’s model blueprint: pin a system prompt, sampling parameters, and context length on top of existing weights, then ollama create a new local name. The CLI, native API, and OpenAI-compatible layer all use that name—you do not paste a long system string in every client.
Instructions are case-insensitive; docs use uppercase for readability. Order does not matter; put FROM first by convention.
Minimal example
Save as Modelfile (extension optional) and, in that directory:
The official CLI also accepts ollama create -f Modelfile without a name (see current --help). Inspect the expanded file for an existing model:
The dumped FROM often points at a blob hash, plus the stock TEMPLATE and stop tokens. When you customize, set FROM to a human tag (FROM gemma4:latest) instead of copying the blob path unless you intend to pin that exact blob.
FROM (required)
For GGUF from Hugging Face, check license and chat template first. Background: Hugging Face tutorial.
SYSTEM
This becomes the template’s system message—persona and hard rules:
A later API system field or messages[role=system] may override or stack depending on the template. Put stable rules in the Modelfile; keep the request for the actual task.
PARAMETER
PARAMETER <name> <value>. Common ones:
The OpenAI layer has no num_ctx field—bake it into a created model. Larger context uses more VRAM (Models).
MESSAGE, TEMPLATE, and the rest
MESSAGE user / MESSAGE assistant add few-shot turns. TEMPLATE is a Go template with {{ .System }}, {{ .Prompt }}, {{ .Response }}. Do not casually edit a Library model’s template unless you imported a bare GGUF.
Also: ADAPTER for LoRA, LICENSE for legal text, REQUIRES for a minimum Ollama version (e.g. 0.14.0).
How this shows up in the API
After ollama create:
/v1/chat/completions with "model": "kenhuang-tutor" works the same. That drifts less than copying a system prompt into every client.
Practical notes
- Persona change → create a new name (
kenhuang-tutor-v2) so you can roll back. - Do not dump a whole manual into
SYSTEM; put long knowledge in RAG (Embeddings, LangChain RAG). - Factual Q&A likes low temperature (0.1–0.4); brainstorming can go higher.
- Full instruction list: Modelfile Reference.
A complete coding-assistant file is in Practical examples.