The speech models from the previous lesson run inside your Python scripts. The language and vision model is different: it runs in Ollama, a separate program that keeps a model loaded and answers requests over HTTP on your own computer. In this lesson you install Ollama, make sure it never uses cloud services, download the course model, learn the one request setting that every course script depends on, and run a readiness check that sends the model a sentence and a picture.
By the end you will have Ollama running in local-only mode, the model
qwen3.5:4b-q4_K_M (a 3.3 GB download), and readiness.py, which reports
on all of it, including whether the model is running on your processor or
your graphics processor.
Before You Start
You need the practice folder and environment from Set Up Python and the
Speech Models; check_setup.py should report every check passing. You also
need about 5 GB of free disk space for Ollama and the model.
A Bridge: Environment Variables for One Session
Programs often read settings from environment variables: named values
that a terminal passes to every program it starts. Ollama reads several,
for example OLLAMA_HOST (the address it listens on) and OLLAMA_NO_CLOUD
(turn off cloud features) (S04). A variable set in a terminal lasts only
for that terminal session. Try it.
In bash or zsh:
export COURSE_DEMO=hello
echo "$COURSE_DEMO"
In PowerShell:
$env:COURSE_DEMO = "hello"
$env:COURSE_DEMO
Both print hello. Open a new terminal and print it again: the line is
empty, because the new session never had it. That is why the course sets
Ollama's permanent settings in a file or in the operating system's settings
rather than in a terminal, and why one check below is to make sure
OLLAMA_HOST is not set to something unexpected.
Step 1: Install Ollama
Use the official installer for your system (S01):
- macOS 14 or later: open
Ollama.dmgfrom ollama.com, drag Ollama to Applications and start it. On first start it offers to put theollamacommand on your path; accept (S63). - Windows 10 22H2 or later: run
OllamaSetup.exe. It installs into your home folder and does not need administrator rights (S65). - Linux: run the install script from the Ollama documentation,
curl -fsSL https://ollama.com/install.sh | sh, then check the service as described there (S64). Read a downloaded script before piping it to a shell if your organisation's policy requires it.
Check the command works in a new terminal:
ollama --version
The course was tested with Ollama 0.40.7. A newer version is likely to work, but if a later lesson behaves differently from its text, the version is the first thing to compare.
Step 2: Keep Ollama Local
By default Ollama listens only on 127.0.0.1:11434, which means only
programs on your own computer can reach it, and its documentation says it
does not see your prompts or data when models run locally (S04). Ollama
also offers cloud-hosted models and web search; this course never uses
them, and you will switch them off so that no course request can reach a
cloud service by mistake.
Create the file ~/.ollama/server.json (on Windows,
%USERPROFILE%\.ollama\server.json) with this content, then quit and
restart Ollama:
{
"disable_ollama_cloud": true
}
On Linux you can instead add Environment="OLLAMA_NO_CLOUD=1" to the
service with sudo systemctl edit ollama and restart it (S04, S64). Ollama
writes "Ollama cloud disabled: true" to its server log at start-up when the
setting has taken effect; the log is ~/.ollama/logs/server.log on macOS,
%LOCALAPPDATA%\Ollama\server.log on Windows, and journalctl -u ollama
on Linux (S63, S64, S65).
Finally, confirm that nothing in your terminal points Ollama elsewhere. This should print an empty line:
echo "$OLLAMA_HOST"
In PowerShell: $env:OLLAMA_HOST. Never set it to 0.0.0.0 for this
course: that would let other computers on your network use your model.
Step 3: Download the Course Model
ollama pull qwen3.5:4b-q4_K_M
ollama list
The pull downloads about 3.3 GB and takes a few minutes to over half an
hour, depending on your connection. ollama list then shows it:
NAME ID SIZE MODIFIED
qwen3.5:4b-q4_K_M d8b0f5e9760c 3.3 GB 6 minutes ago
Why this model and this exact name:
- Qwen 3.5 4B reads both text and images, is licensed Apache 2.0, and was the most accurate of four small open models the course measured on its own images.
- The tag
4b-q4_K_Mnames one specific build: the 4-billion-parameter model with its weights compressed to about 4 bits ("Q4_K_M"). Ollama's shorter tags, such asqwen3.5:4b, can resolve to different builds on different computers (S07), which would make your results differ from the lesson's for reasons that have nothing to do with your code.
Step 4: Turn Thinking Off, in Every Request
Some models, including Qwen 3.5, can "think" before answering: they write a
long hidden chain of reasoning, returned separately as thinking, and only
then the answer (S45). For this course that is harmful. In the course's own
tests, the smaller Qwen 3.5 model, asked a one-line question with thinking
left on, wrote 8,171 tokens of reasoning, filled its whole context window
and returned no answer at all.
So every request in this course sends "think": false on Ollama's native
chat API (S44, S45). If you ever see a request take minutes and come back
empty, check this setting first.
Step 5: Run the Readiness Check
Create ~/voice-practice/set-up-ollama-and-check-readiness, change into
it, and save this as readiness.py:
"""Check that Ollama and the course vision model are ready.
Talks only to Ollama on this computer (127.0.0.1:11434). Sends one text
request and one image request with thinking turned off, and reports
whether the model is running on the CPU or the GPU. Writes nothing.
"""
import base64
import io
import sys
import time
import httpx
from PIL import Image, ImageDraw, ImageFont
OLLAMA = "http://127.0.0.1:11434"
MODEL = "qwen3.5:4b-q4_K_M"
OPTIONS = {"temperature": 0, "seed": 20261021, "num_ctx": 8192}
results = []
def check(name: str, ok: bool, detail: str) -> bool:
results.append(ok)
print(f"{'PASS' if ok else 'FAIL'} {name:20} {detail}")
return ok
def chat(client: httpx.Client, content: str, images: list[str] | None = None, schema: dict | None = None) -> dict:
message = {"role": "user", "content": content}
if images:
message["images"] = images
body = {"model": MODEL, "messages": [message], "stream": False, "think": False, "options": OPTIONS}
if schema:
body["format"] = schema
started = time.perf_counter()
reply = client.post("/api/chat", json=body)
reply.raise_for_status()
data = reply.json()
data["wall_seconds"] = time.perf_counter() - started
return data
def test_image() -> str:
"""A label with a known number, as base64-encoded PNG.
It is deliberately not tiny: at 640 x 240 pixels the course model read
"DOCK 42" as 2, because so small an image gives it too little detail.
"""
image = Image.new("RGB", (1000, 400), "white")
ImageDraw.Draw(image).text((60, 120), "DOCK 42", fill="black", font=ImageFont.load_default(size=120))
buffer = io.BytesIO()
image.save(buffer, format="PNG")
return base64.b64encode(buffer.getvalue()).decode()
def main() -> None:
client = httpx.Client(base_url=OLLAMA, timeout=httpx.Timeout(600.0, connect=5.0))
try:
version = client.get("/api/version").json()["version"]
except httpx.ConnectError:
check("Ollama server", False, f"nothing is listening at {OLLAMA}; start the Ollama app or service")
sys.exit(1)
check("Ollama server", True, f"version {version} at {OLLAMA}")
names = [m["name"] for m in client.get("/api/tags").json()["models"]]
if not check("course model", MODEL in names, MODEL if MODEL in names else f"not pulled; run: ollama pull {MODEL}"):
sys.exit(1)
show = client.post("/api/show", json={"model": MODEL}).json()
check("vision capability", "vision" in show.get("capabilities", []), ", ".join(show.get("capabilities", [])))
text = chat(client, "Reply with the single word: ready")
answer = text["message"]["content"].strip()
check("text request", "ready" in answer.lower(),
f"{answer!r} in {text['wall_seconds']:.1f} s ({text['eval_count']} tokens, thinking {'off' if not text['message'].get('thinking') else 'ON'})")
schema = {"type": "object", "properties": {"number": {"type": "integer"}}, "required": ["number"]}
image = chat(client, "What number follows the word DOCK in this image?", [test_image()], schema)
reply = " ".join(image["message"]["content"].split()) # the JSON may span several lines
check("image request", reply.replace(" ", "") == '{"number":42}',
f"{reply} in {image['wall_seconds']:.1f} s ({image['prompt_eval_count']} prompt tokens)")
loaded = [m for m in client.get("/api/ps").json()["models"] if m["name"] == MODEL]
if loaded:
on_gpu = loaded[0].get("size_vram", 0)
where = "CPU only" if on_gpu == 0 else "GPU (all or part)"
print(f"INFO {'processor':20} {where}; run 'ollama ps' to see the split")
print(f"\n{sum(results)} of {len(results)} checks passed")
if not all(results):
sys.exit(1)
if __name__ == "__main__":
main()
The important parts:
OLLAMAandMODEL. The address is Ollama's default local address; the model name is the exact tag you pulled.OPTIONS. Temperature 0 and a fixed seed make answers as repeatable as the model allows, andnum_ctxsets the context window (how much text and image the model can consider at once) to 8,192 tokens, the size the course uses everywhere.chat()builds one request for Ollama's/api/chatendpoint: the message, optional images as base64 text,"stream": falseso the whole answer arrives at once,"think": false, and, when given, a JSON Schemaformatthat forces the reply into a fixed shape (S44). You will study each of these in their own lessons; here they are just used.test_image()draws a label reading "DOCK 42". It is 1,000 × 400 pixels on purpose. A first version at 640 × 240 pixels was read by the model as "2" every time, because so small an image gives the model too little detail to work with; Send Images to a Vision-Language Model measures this.- The checks run in order and stop early when a later check would be
meaningless: no server, no model, then the capabilities, a text request,
an image request, and finally
/api/ps, which says where the loaded model lives.size_vramof 0 means it is entirely in ordinary memory and running on the processor.
Run it with the course environment:
~/voice-practice/.venv/bin/python readiness.py
In PowerShell: & "$HOME\voice-practice\.venv\Scripts\python.exe" readiness.py.
Illustrative output from the author's first run (macOS, Apple M2, a busy computer, with the model not yet loaded):
PASS Ollama server version 0.40.7 at http://127.0.0.1:11434
PASS course model qwen3.5:4b-q4_K_M
PASS vision capability completion, vision, tools, thinking
PASS text request 'ready' in 20.7 s (2 tokens, thinking off)
PASS image request { "number": 42 } in 16.7 s (428 prompt tokens)
INFO processor GPU (all or part); run 'ollama ps' to see the split
5 of 5 checks passed
- The first text request took 20.7 s because Ollama loaded the model from disk first; the second run took 2.0 s. Ollama keeps a model loaded for five minutes after its last use by default (S04).
428 prompt tokensis how much of the context window the image and the question used. Remember the number; image size will matter a great deal.visionmust appear among the capabilities, andthinking offmust appear on the text line.
Then look at where the model is running:
ollama ps
NAME ID SIZE PROCESSOR CONTEXT RUNNER UNTIL
qwen3.5:4b-q4_K_M d8b0f5e9760c 3.4 GB 100% GPU 8192 llamacpp 4 minutes from now
100% GPU means the whole model is in the graphics processor's memory,
100% CPU that it is running on the processor, and a split such as
48%/52% CPU/GPU that it did not fit entirely (S04). On a computer without
a supported graphics processor you will see 100% CPU. Speech lessons and
text requests are comfortable that way. Image requests are not: in the
course's CPU-only test each new image took about two to five and a half
minutes with this model, so the image lessons recommend a GPU or Apple
silicon and give a smaller CPU-only plan for everyone else, as
Send Images to a Vision-Language Model
explains.
Diagnose Six Common Setup Failures
These are the failures learners meet most often across this lesson and the previous one. Each shows the evidence you would see.
| # | Evidence | Your diagnosis |
|---|---|---|
| 1 | FAIL Ollama server nothing is listening at http://127.0.0.1:11434 | ? |
| 2 | FAIL course model not pulled; run: ollama pull qwen3.5:4b-q4_K_M | ? |
| 3 | FAIL PortAudio ... libportaudio ... on Linux | ? |
| 4 | A recording made in a later lesson reports "silence (all zeros)" on a Mac | ? |
| 5 | Error processing file '.../phontab': No such file or directory, naming a folder that is not on your computer | ? |
| 6 | FAIL course environment and numpy not installed from check_setup.py, although you installed everything | ? |
Write a cause and a safe next check for each before opening the answer.
Answer and Reasoning
- Ollama is not running (or not yet started after a restart). Start
the Ollama app, or on Linux check
systemctl status ollama; then run the check again. Do not changeOLLAMA_HOSTto "fix" it. - The model has not been downloaded, or was pulled under a different
tag. Run the pull command exactly as printed, then
ollama list. - PortAudio is missing. Install your distribution's
libportaudio2package. Only microphone and playback need it, so everything else can continue meanwhile. - The terminal app has no microphone permission, or the wrong input device is selected. Check the operating system's privacy settings for your terminal and the device list; the recording lesson covers this.
- espeak-ng cannot use its data folder, almost always because the path
is 160 characters or longer. Use the short copy in
~/voice-practice/models/espeak-ng-data, asdownload_models.pymakes. - The script was run with a different Python. Run it with
~/voice-practice/.venv/bin/python(or the Windows equivalent); nothing needs reinstalling.
In every case the evidence names the stage that failed. Fix that stage and rerun the same check, rather than reinstalling everything.
Reset and Cleanup
Leave Ollama installed and the model downloaded: the voice assistant
module, starting with
Call a Local Language Model,
and the vision and extraction modules use them. readiness.py writes nothing. When
you finish the course, ollama rm qwen3.5:4b-q4_K_M removes the model, and
the Ollama documentation for your system describes a full uninstall (S63,
S64, S65).
References
- Ollama releases, installation and uninstallation (S01, S63, S64, S65)
- Local-only mode, default address,
ollama psand model storage (S04) - The chat API, images and
think(S02, S44, S45); model tags (S07)