liveBook · Manning

Modelfile

As explained in Build Applications with Local AI Models on a Mac

A Modelfile is Ollama's declarative file format for specifying the base model, prompts, parameters, and other settings of a custom model.

A Modelfile is a plain-text recipe for a custom Ollama model. It names a base model and bundles choices such as a system prompt and generation parameters. Once created, the customized model has its own name, so you can run it without re-entering those settings. section 13.4 section 13.4.1

# The base model to build upon
FROM gemma3:4b

# Parameter settings
PARAMETER temperature 0.8
PARAMETER top_p 0.9
PARAMETER repeat_penalty 1.1

# The system prompt (use triple quotes for multi-line)
SYSTEM """You are a friendly study buddy who explains concepts simply
and encourages the learner. Always use analogies and examples from
everyday life. When the user seems confused, break the concept down
into smaller steps. Celebrate their progress."""

# Template (optional, for advanced customization)
# TEMPLATE """{{ .System }}
# {{ .Prompt }}"""

# License information (optional)
# LICENSE """MIT License..."""

Read the recipe from top to bottom: FROM is required and selects the base model; PARAMETER sets defaults; SYSTEM supplies behavior instructions. The commented TEMPLATE and LICENSE lines illustrate optional settings. section 13.4.1

To make a reusable study assistant:

  • Save a plain-text file named Modelfile.studybuddy. Start with FROM gemma3:4b, then add a SYSTEM instruction asking for simple, encouraging explanations. Add PARAMETER temperature 0.8 and PARAMETER top_p 0.9 if you want those defaults. section 13.4.3
  • Run ollama create studybuddy -f Modelfile.studybuddy to register the named model in your local Ollama installation. section 13.4.3
  • Run ollama run studybuddy to try it. The named model can also be used through the API or in a Streamlit chatbot. section 13.4.3

Change the job, change the recipe

A study assistant can use a patient SYSTEM prompt and temperature 0.7. A code reviewer can instead use instructions that prioritize bugs, security, performance, readability, and style, with temperature 0.3. Both use the same Modelfile pattern: a base model plus settings for a particular job. section 16.3.1 section 13.4.3

A Modelfile can also point FROM to an exported GGUF file. In that workflow, fine-tuning happens first; the Modelfile and ollama create then register the result for local use. Merely writing a Modelfile does not perform the training. section 16.6.4 section 17.7.1

How Build Applications with Local AI Models on a Mac covers it

How deep it goes
Works through required and optional instructions, then shows creation and running commands; defers prompt-template customization as advanced.
Examples
Uses study-assistant, pirate-tutor, and code-reviewer configurations, plus Ollama commands to create and run named models.
What it assumes
Assumes a local Ollama installation and a base model, while introducing the Modelfile format from its required FROM instruction.
What you can do after
Build it from scratch with a plain-text Modelfile, then create and run the named model using Ollama.
How it connects
Connects system prompts and generation parameters to Ollama models, and connects exported GGUF files to local deployment after fine-tuning.

Also explained in

Compare how 2 books explain Modelfile →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Applications with Local AI Models on a Mac. The section links point to the parts of the book it draws on.