Skip to content

Practice 2 — Slash commands inside `ollama run`

Duration: ~15 min Prerequisites: Practice 1 — First contact with ollama run

The >>> prompt of ollama run is more than a chat box. It is a complete control panel for the running model, accessed through slash commands. This practice walks through all of them, with one mini-exercise at the end that ties them together.

Every command works without any additional download, configuration or framework. It is all already there, free, the moment you have ollama run open.

Start a session that we will keep open for the whole practice:

Terminal window
ollama run llama3.1:8b

Then type /? (or /help) to see the menu of commands:

>>> /?
Available Commands:
/set Set session variables
/show Show model information
/load <model> Load a session or model
/save <model> Save your current session
/clear Clear session context
/bye Exit
/?, /help Help for a command
/? shortcuts Help for keyboard shortcuts

Two families of commands: /show reads, /set writes. The rest manage the session itself.

Part A — Inspecting the model with /show

Section titled “Part A — Inspecting the model with /show”

These commands change nothing. They only print information.

>>> /show info
Model
architecture llama
parameters 8.0B
context length 131072
embedding length 4096
quantization Q4_K_M
...

What you see is the specsheet of the loaded model: family, parameter count, quantization, context window. This connects directly to the catalogue annex and the quantization annex.

>>> /show parameters
Model defined parameters:
stop "<|start_header_id|>"
stop "<|end_header_id|>"
stop "<|eot_id|>"

The stop tokens the model uses to mark the end of a turn. You will recognise these special tokens from the discussion in chapter 09 about tool-calling formats.

>>> /show modelfile
# Modelfile generated by "ollama show"
FROM llama3.1:8b
TEMPLATE """{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>
...
"""
PARAMETER stop "<|start_header_id|>"
...

This is the chat template — the Go template that Ollama uses to format every conversation before sending it to the model. The {{ if .Tools }} block (visible if you scroll) is the exact spot where tool schemas get injected for tool-calling models. Reading this now is the cheapest possible preview of chapter 09’s explanation of Ollama’s invisible work.

>>> /show system
No system message was specified for this model.
>>> /show template
{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>...

system shows the current system message (empty by default). template shows only the template part of the modelfile.

Part B — Tweaking behaviour with /set parameter

Section titled “Part B — Tweaking behaviour with /set parameter”

This is where you feel parameters change the model’s behaviour, live, without restarting anything.

Ask the same prompt three times with three different temperatures.

>>> /set parameter temperature 0.1
Set parameter 'temperature' to '0.1'
>>> Give me a one-line slogan for a coffee shop.
"Sip the perfect brew."
>>> /set parameter temperature 0.9
Set parameter 'temperature' to '0.9'
>>> Give me a one-line slogan for a coffee shop.
"Wake up your senses, one warm cup at a time."
>>> Give me a one-line slogan for a coffee shop.
"Where every sip is a moment of peace."

At temperature 0.1 the answer is nearly the same every time. At 0.9 you get different wording on each call. This is the same temperature parameter you will pass to client.chat(options={"temperature": ...}) in the Python demos.

>>> /set parameter num_ctx 8192
Set parameter 'num_ctx' to '8192'

num_ctx is how many tokens the model can read in one shot. Llama 3.1 supports up to 131072 (yes, 131k), but Ollama caps it lower by default to save VRAM. Bigger context = more VRAM. If you have a small GPU and the model behaves oddly mid-conversation, lowering this often helps.

>>> /set parameter num_predict 50
>>> Tell me everything about the French Revolution.
[answer is cut off at ~50 tokens]

Useful in production to cap costs when you only want short replies.

>>> /set parameter seed 42
>>> /set parameter temperature 0.8
>>> Give me a one-line slogan for a coffee shop.
"Stir up your day with our perfect cup."
>>> Give me a one-line slogan for a coffee shop.
"Stir up your day with our perfect cup."

With a fixed seed, even at high temperature, you get the same answer every time. Essential for tests and for the comparator demo (chapter 08b).

>>> /set parameter top_k 10
>>> /set parameter top_p 0.5

Two ways to filter the model’s candidate words. We covered them in chapter 01. You can tweak them here interactively before deciding what to hard-code in Python.

Part C — Changing the role with /set system

Section titled “Part C — Changing the role with /set system”
>>> /set system You are a pedagogical assistant. Answer every question with one short paragraph followed by a worked example.
Set system message.
>>> What is recursion?
Recursion is a technique where a function calls itself with a smaller version of the problem...
Example: factorial(3) = 3 * factorial(2) = 3 * (2 * factorial(1)) = 3 * 2 * 1 = 6.
>>> /set system You always answer like a pirate.
Set system message.
>>> What is recursion?
Arrr matey, recursion be when a function calls itself...

You changed the system prompt with no restart. This is exactly the same {"role": "system", "content": "..."} message that the Python demos prepend to their message list.

>>> Hi, my name is Alice.
Hello Alice, nice to meet you!
>>> /clear
Cleared session context
>>> What is my name?
I don't have access to your name. Could you tell me what it is?

/clear removes the conversation history but keeps the model loaded and the parameters you set. Useful when you want a fresh chat without restarting ollama run.

>>> /save pirate-tutor-v1
Created new model 'pirate-tutor-v1'
>>> /bye
# In a new terminal:
ollama run pirate-tutor-v1
>>> Hi.
Ahoy! What be ye wantin' to learn today?

/save snapshots the current parameters + system prompt as a new named model. Next time, ollama run pirate-tutor-v1 brings the whole setup back without re-typing anything. The new model is just a thin wrapper on top of llama3.1:8b — it does not duplicate the weights on disk.

Verify with:

Terminal window
ollama list
# you should see pirate-tutor-v1 in the list, with a size of a few KB

Cleanly unloads the model from memory and closes the session.

Mini-exercise — build your first custom assistant

Section titled “Mini-exercise — build your first custom assistant”

In one continuous session, do this:

ollama run llama3.1:8b
>>> /set parameter temperature 0.3
>>> /set parameter num_predict 200
>>> /set system You are a Python tutor for absolute beginners. Always answer in 3 short paragraphs: definition, simple example, common mistake.
>>> /save python-tutor
>>> /bye

Then, in a fresh terminal:

Terminal window
ollama run python-tutor
>>> What is a list comprehension?
[short pedagogical answer in 3 paragraphs]

You have just built your first custom Ollama model — a wrapper of llama3.1:8b configured for a specific use case. Zero code, zero installation. This is exactly the technique that powers the Demo 4 system prompts editor, only that demo edits the system prompt at runtime instead of saving it as a model.

CommandWhat it does
/? or /helpList all commands
/show infoSpecsheet of the loaded model
/show parametersCurrent sampling and stop parameters
/show modelfileFull chat template (preview of ch 09)
/show systemCurrent system message
/show templateJust the template part of the modelfile
/set parameter temperature <0.0-2.0>Determinism vs creativity
/set parameter num_ctx <int>Context window in tokens
/set parameter num_predict <int>Max tokens in the reply
/set parameter seed <int>Reproducible output (with temperature > 0)
/set parameter top_k <int>Keep only top-k candidate tokens
/set parameter top_p <0.0-1.0>Nucleus sampling
/set system <text>Change the system prompt live
/clearWipe history, keep model and parameters
/save <name>Snapshot current setup as a new named model
/load <name>Switch to a previously saved model
/byeExit and unload the model
  • Every concept the Python demos pass via API parameters (temperature, num_ctx, num_predict, seed, system message) is already available as a slash command in ollama run.
  • You can build a custom pedagogical model in 30 seconds, no code, just /set + /save.
  • The chat template that drives every conversation is a readable Go template you can inspect with /show modelfile.

Next: feel the size and family differences

Section titled “Next: feel the size and family differences”

You have explored one model in depth. The next practice does the opposite: it touches three different models in a row to make you feel how size and specialty change the experience.

Practice 3 — Compare 3 models in your terminal →