Ollama Modelfile Sample

From Coolscript
Revision as of 18:04, 1 May 2026 by Admin (talk | contribs) (Created page with "= Ollama Modelfile Cheat Sheet = == Basic Structure == A Modelfile is a recipe for building a model. <pre> FROM <base_model> # Optional settings PARAMETER <key> <value> SYSTEM <text> TEMPLATE <text> ADAPTER <path> LICENSE <text> MESSAGE <role> <text> </pre> == FROM (Required) == Base model you build on. <pre> FROM llama3 FROM mistral FROM ./local-model.gguf </pre> == PARAMETER == Controls runtime behavior. === Common Parameters === <pre> PARAMETER temperatur...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Ollama Modelfile Cheat Sheet

Basic Structure

A Modelfile is a recipe for building a model.

FROM <base_model>

# Optional settings
PARAMETER <key> <value>

SYSTEM <text>

TEMPLATE <text>

ADAPTER <path>

LICENSE <text>

MESSAGE <role> <text>

FROM (Required)

Base model you build on.

FROM llama3
FROM mistral
FROM ./local-model.gguf

PARAMETER

Controls runtime behavior.

Common Parameters

PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER top_k 40
PARAMETER num_ctx 4096
PARAMETER repeat_penalty 1.1
PARAMETER seed 42
PARAMETER num_predict 128

Description

  • temperature – randomness (0 = deterministic, 1 = highly random)
  • top_p – nucleus sampling probability cutoff
  • top_k – limits token selection pool
  • num_ctx – context window size
  • repeat_penalty – reduces repetition
  • num_predict – max tokens to generate

SYSTEM

Defines assistant behavior.

SYSTEM You are a helpful assistant that explains things simply.

TEMPLATE

Controls prompt formatting.

TEMPLATE """
{{ if .System }}<|system|>
{{ .System }}
{{ end }}

<|user|>
{{ .Prompt }}

<|assistant|>
"""

MESSAGE

Few-shot examples.

MESSAGE user What is 2+2?
MESSAGE assistant 4

ADAPTER

Attach LoRA adapters.

ADAPTER ./my-lora

LICENSE

Attach a license.

LICENSE MIT

Full Example

FROM llama3

PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 4096

SYSTEM You are a precise and concise coding assistant.

TEMPLATE """
{{ if .System }}<|system|>
{{ .System }}
{{ end }}

<|user|>
{{ .Prompt }}

<|assistant|>
"""

MESSAGE user Write a Python function to add two numbers.
MESSAGE assistant def add(a, b): return a + b

Build and Run

ollama create mymodel -f Modelfile
ollama run mymodel

Common Pitfalls

  • Missing FROM → build fails
  • Too large num_ctx → high memory usage
  • Incorrect TEMPLATE → broken responses
  • High temperature → hallucinations
  • Low temperature → overly rigid output

Mental Model

  • FROM = base model
  • SYSTEM = behavior
  • TEMPLATE = prompt structure
  • PARAMETER = tuning
  • MESSAGE = examples
  • ADAPTER = extensions