Chapter 18 · Hands-on: set up your AI workbench
Check your workbench end to end
Before building projects, confirm each piece works on its own: terminal, Python, the model and a script.
Chapter 18 · Hands-on: set up your AI workbench
Before building projects, confirm each piece works on its own: terminal, Python, the model and a script.
Check them in order. One red light is easiest to fix first.
Each piece of the workbench has to work on its own. If you test them in order, a red light tells you exactly where to look.
Work from the first light to the last. Open a terminal and go to my-ai-project. Fix each red light before you move on, because later lights depend on earlier ones.
Confirm you are inside your project folder.
pwd
lsCheck: pwd ends in my-ai-project, and ls lists your files such as run.py or ask.py.
Activate the environment if the prompt does not start with (.venv), then ask Python for its version.
.venv\Scripts\Activate.ps1
python --versionCheck: the prompt starts with (.venv) and a Python 3 version prints.
List your downloaded models. If the runner is not running, start it first.
ollama listCheck: your model appears in the list with its size.
Save this as check.py in my-ai-project. It checks the environment, the runner, your models and a real reply, and prints PASS or FAIL for each, with a fix for every FAIL. It sends one tiny message to your local model and nothing else.
import sys
import requests
BASE = "http://localhost:11434"
def light(name, ok, hint=""):
print(("PASS " if ok else "FAIL ") + name + ("" if ok else "\n -> " + hint))
return ok
results = []
results.append(light("Python runs", True))
results.append(light(
"Virtual environment is active",
sys.prefix != sys.base_prefix,
"activate it first (the prompt should start with (.venv))",
))
models = []
try:
models = requests.get(BASE + "/api/tags", timeout=5).json().get("models", [])
results.append(light("Model runner answers", True))
except requests.RequestException:
results.append(light("Model runner answers", False, "start the runner app, or run: ollama serve"))
results.append(light("At least one model is downloaded", len(models) > 0, "download one with: ollama pull <model name>"))
if models:
name = models[0]["name"]
try:
reply = requests.post(
BASE + "/api/chat",
json={"model": name, "messages": [{"role": "user", "content": "Say OK."}], "stream": False},
timeout=120,
)
reply.raise_for_status()
results.append(light("Model " + name + " replied", True))
except requests.RequestException as error:
results.append(light("Model " + name + " replied", False, str(error)))
print()
print("All green. Your workbench is ready." if all(results) else "Some checks failed. Fix the first FAIL and run again.")
sys.exit(0 if all(results) else 1)Check: the last line says: All green. Your workbench is ready.
Run python check.py any time something stops working, for example after restarting your computer. The later project lessons assume it passes.
python check.pyCheck: you know where check.py lives and how to rerun it.
After each check, mark the light. Any red light shows the usual fixes.
Light 1: Terminal. You can open a terminal and move into my-ai-project.
Light 2: Python and virtual environment. python --version works and the prompt starts with (.venv).
Light 3: Model runner and model. ollama list shows at least one model and the runner is running.
Light 4: Script talks to the model. python check.py ends with ‘All green’.
0 of 4 lights green.
Why check the lights in order?
check.py says the runner does not answer. What do you do?
When should you rerun check.py?