Feedback

Chat Icon

Local AI Engineering with Ollama

Run, understand, customize, fine-tune, and build agentic apps on your own hardware

Building, Running, and Sharing Custom Models for Ollama (Modelfile)
60%

Step 5: Teach the Format by Example with MESSAGE

Few-shot learning is a prompt engineering technique: instead of describing the format you want in words, you show the model a few worked examples, each one an input paired with the answer you want back. The model reads the pattern in those examples and copies it.

You already set the rules in the system prompt, but a small model often reads those rules without following them closely, so a concrete example it can match beats an instruction it can drift from. The "few shots" are the examples themselves, and small models tend to follow them more closely than they follow written rules. Here you use it to lock the shape of the commit message.

Rules in SYSTEM tell the model what to do. MESSAGE shows it. Each MESSAGE line adds one turn of example conversation that rides along with every request. You write pairs: a user example input, then the assistant answer you want. The model copies the pattern. Keep the examples few and short, since they use some of your context window on every request.

These are the 3 pairs we're going to use:

MESSAGE user added a retry with backoff to the HTTP client and a test for it

MESSAGE assistant feat(http): add retry with backoff to client

MESSAGE user fixed a typo in the README install section

MESSAGE assistant docs(readme): fix typo in install section

MESSAGE user renamed getUser to fetchUser across the codebase, no behavior change

MESSAGE assistant refactor: rename getUser to fetchUser

Create the new Modelfile:

cat < $HOME/commitwriter/Modelfile
# commitwriter - turns a code change into a commit message
FROM granite4.1:3b

SYSTEM """
You write git commit messages in Conventional Commits format.
Read the user's description or code diff. Reply with one commit message and nothing else.

Use this shape:
type(scope): short summary

An optional body that explains what changed and why.

Rules:
- type is one of: feat, fix, docs, refactor, test, chore.
- scope is optional and lowercase.
- the summary is under 60

Local AI Engineering with Ollama

Run, understand, customize, fine-tune, and build agentic apps on your own hardware

Enroll now to unlock all content and receive all future updates for free.