Running Local LLMs With Ollama

Customising Models With Ollama

Modelfile Introduction

In this lesson, you’ll discover what a Modelfile is and how to tailor open-source models using Ollama. We’ve already covered running models locally, explored Ollama’s commands and features, built AI applications, and switched from Ollama to OpenAI keys for production deployments.

Recap

  • Running models locally with Ollama
  • Key commands and features
  • Building AI-powered applications for production

The image is a slide titled "Recap" with three points: running models locally with Ollama, various commands and features, and building AI applications for production.


Use Case: Gromor’s Customized Model

Gromor, an investment and portfolio management firm, wants its AI assistant to interpret monetary values in Indian rupees. By creating a Modelfile, Gromor can instruct the base model to output “₹100” instead of “100” when dealing with rupees.

The image illustrates a process where open-source models interpret the number "100" as Indian Rupees, resulting in "₹100."


Modelfile vs. Dockerfile

A Modelfile is to Ollama what a Dockerfile is to Docker.

The image shows an analogy comparing Docker with a Modelfile, suggesting a comparison between a Docker file and a Modelfile.

Note

Both files start from a base image and layer on custom instructions to produce a final artifact.

Dockerfile Workflow

The image illustrates an analogy between Docker and another concept, showing a process flow from a base image to defining steps to build a container image.

  1. FROM ubuntu:20.04
  2. RUN apt-get update && apt-get install -y python3
  3. Other build steps…

Modelfile Workflow

  1. FROM <model name>:<tag>
  2. PARAMETER declarations
  3. SYSTEM and MESSAGE instructions

Common Modelfile Fields

Below are the most frequently used instructions in a Modelfile:

1. FROM

Specifies the base model image to extend:

The image shows a diagram with two labeled circles, "Base Model" and "New Model," connected by an arrow, indicating a transformation or progression.

FROM facebook/opt-1.3b:latest

2. PARAMETER

Declare hyperparameters that control the model’s output:

The image describes three parameters for a language model: "temperature" for creativity, "num_ctx" for the number of context tokens, and "top_k" for response diversity.

ParameterPurposeExample
temperatureCreativity vs. precision (0–1)0.2 for factual
num_ctxMax tokens in context512
top_kRestrict candidate tokens per generation50
# Lower temperature yields more factual outputs
PARAMETER temperature 0.2

Warning

Setting temperature too high (e.g., ≥0.9) can produce overly creative or inconsistent responses.

3. SYSTEM

Define a high-level system message to steer the model’s role:

SYSTEM "You are a financial assistant fluent in INR notation."

4. MESSAGE

Provide dialogue history to establish context:

The image shows a text exchange between a user and an assistant discussing fictional locations, confirming Gotham City is in New Jersey and Wayne Manor is in Gotham City, but Metropolis is not in New Jersey.

MESSAGE user "Where is Wayne Manor?"
MESSAGE assistant "Wayne Manor is in Gotham City, New Jersey."

Next Steps

You now know how to build a Modelfile with FROM, PARAMETER, SYSTEM, and MESSAGE instructions.
For a comprehensive list of Modelfile directives, see the Ollama Modelfile documentation.

Watch Video

Watch video content

Previous
Section Introduction