Maximilian: Creating customized versions,
adjusted versions of open Large Language Models
as you learned it in the previous lectures,
is one of the big advantages
or core features offered by Ollama.
And you saw how you can set the system message or parameters
or even a chat history
and then save that as a new model
to reuse it for future use.
Now, besides using set and save
to configure and save a model,
you can also use another approach.
You can create a so-called model file,
and here I'm doing this in Visual Studio Code,
which is simply a text editor.
You can also use a regular text editor.
You don't need a code editor for this,
and you can do this anywhere on your system
in any folder of your choice.
This is also a file without a file extension.
It's just a file called Modelfile
because Ollama has this concept of model files,
which in the end is inspired by Docker files.
Now you don't need to know Docker.
If Docker files don't tell you anything, that's no problem.
The idea behind these model files is essentially
that you can configure models,
adjust models just as we did it with /set,
but without doing it in the command line,
and then you can load models based on that model file.
So you can simply configure a model
in a more convenient way here, so to say.
Therefore, every model file starts with a from instruction,
which defines the base model you want to build up on.
In my case here, gemma3, and then 12b, and then -it-qat.
So using that same identifier I used all the time.
That will tell Ollama
that this is the general AI model I want to use,
but now I can overwrite
or adjust certain settings about this model.
For example, as you also see in the official docs,
which unfortunately are only available on GitHub.
You'll find a link
to that model file documentation attached.
For example, you can set parameters
with the parameter instruction.
You can set a system message with the system instruction.
You can also set more advanced things,
but I'll get back to one advanced concept,
the template, a little bit later.
For now, I'll focus on parameter, system, and also message.
So let's do that here.
Let's set a parameter
and I'll set the num_ctx parameter,
which defines the available context window length,
and I'll set that to 10,000 tokens.
We can also set another parameter.
For example, the temperature, to let's say 0.5.
The default for the Gemma model
at this point of time is one actually.
Here I'm setting it to 0.5
to make it a bit less creative.
And don't forget, you'll find the default params
for the model you're using in the Ollama models catalog
on the detail page of a given model.
There under params, you find the default parameters.
So here for Gemma 3, the default temperature is one.
Now I'm setting it to 0.5 here,
and I'm doing that through that parameter instruction
in that model file,
and that is one of the officially supported instructions.
Of course, you can only include
the instructions you find here
because these are the only instructions
Ollama will understand.
I'll also add a system message,
and that can of course, be anything you want.
It can be a short one, it can be a long one,
like, "You are a friendly assistant.
You will not answer any questions related to LM Studio."
Now, you should make sure that it's all in one line.
Here, it's getting wrapped by my code editor,
but that's just a visual wrap.
Technically, it's all in one line,
and you should ensure that this is the case,
because if you would split it across multiple lines,
this would be interpreted as a new instruction,
but an unknown instruction
because Ollama only understands from, parameter, system,
and whatever else is specified here.
So that's why that should all be in one line.
Again, here it looks like it's in a new line
because my code editor breaks it
across multiple lines visually, but it is in one line,
as you can also tell by the line numbers.
What's also an interesting setting is the message setting.
This allows you to add messages to this model file
and therefore, to the model you'll build based on that file.
And for that, remember that a couple of lectures ago
when I first showed you the /save command,
I did that to save a chat history
and to reuse that chat history.
Here, we can bake a chat history into this model file
and that history will then be used
by any models we build based on that file,
which is something I'll show you in a second.
Now, after message, you should specify who sent the message,
and that can either be user, if it's you,
if you want to simulate that you sent the message to the AI,
or assistant if you want to simulate
or kind of fake that the AI assistant sent the message.
So here we could, for example, send a user message
and say something like, "Hi, this is a question
submitted via the contact form on the website."
Again, there is no real line break here
and there shouldn't be one.
It's just a visual line break by my editor.
And then I'll add another message here,
assistant, "Hi, thanks for contacting us!"
And now that would be some made up chat history
with which we always start
when we run this adjusted model version,
which we're building here with that model file.
And that could therefore,
be one example model file you wanna build.
The question now is how do we now translate this model file
into an actual model we can run with the Ollama command?