Creating Custom Models with Modelfiles
Just like Docker uses a Dockerfile to build custom containers, Ollama uses a Modelfile to define custom system instructions, adjust model parameters, and configure default context lengths.
1. Writing your First Modelfile
Create a text file named Modelfile (no extension) in your workspace:
# 1. Specify the base model
FROM qwen2.5:7b
# 2. Adjust parameters (e.g. context window size to 8k tokens)
PARAMETER num_ctx 8192
PARAMETER temperature 0.3
# 3. Define the system prompt instruction
SYSTEM """
You are a private company support bot. You must follow these rules:
1. Always reply in English.
2. Only write answers if they relate to developer setup instructions.
3. Be professional and concise.
"""2. Compiling the Model via CLI
Compile your Modelfile into a custom model name using the ollama create command:
# Compile and name your model "company-helper-bot"
ollama create company-helper-bot -f ./Modelfile3. Running and Verifying
Verify that your custom model is registered:
ollama listYou will see company-helper-bot listed. Launch and test the model in your terminal:
ollama run company-helper-botPublished on Last updated: