What a Modelfile is
A Modelfile is to Ollama what a Dockerfile is to Docker: a small text file that derives a customized model from a base. You bake in a system prompt, default parameters, few-shot examples, even a LoRA adapter, then build with ollama create. The result is callable as a regular model: ollama run my-assistant.
Instructions you'll actually use
| Instruction | Required? | Purpose |
|---|---|---|
FROM | Yes | Base model name, GGUF file path, or safetensors directory |
SYSTEM | Optional | System prompt baked into every chat |
PARAMETER | Optional | temperature, num_ctx, top_p, top_k, repeat_penalty, seed, stop, num_predict, min_p |
TEMPLATE | Optional | Go template for prompt formatting (advanced — usually inherit from FROM) |
ADAPTER | Optional | Apply a LoRA adapter (safetensor or GGUF) |
MESSAGE | Optional | Few-shot examples (role: user / assistant / system) |
When a Modelfile pays off
- You're building a single product around a model and want one consistent system prompt across all callers.
- You want a stable
num_ctxdefault (Ollama's defaults often undershoot; 8192 or 16384 is a more practical baseline). - You want named variants —
my-coder,my-summarizer,my-translator— that share the same base model but differ in system prompt and parameters.
When to skip it
If you're going to send a system prompt with every API call anyway, a Modelfile adds a layer to maintain. The Modelfile pays off when you want to name a configuration so callers don't have to know it.