0%

Taking It Home

Run the Capstone Locally

Everything so far has run inside this site, against a model that gives the same answer every time. This lesson takes the project home: onto your own computer, with its tests, and then with one real call to a real provider using your own key. Nothing in it is graded, and nothing later in the course depends on it. If you cannot set up Python on your own machine right now, read the steps and stop at the end of this page.

The project has a README.md written for exactly this. Open it in the project editor now. It is the runbook you follow at home, and this page explains each step.

Take the project off the site

Use Download project while signed in, as you did at the end of Python in Practice. You get a ZIP of your workspace. Extract it into a new, empty folder, and open a in that folder. Every command below starts there.

A fresh environment and the tests

Create a virtual environment and install the development requirements into it, calling the environment’s own Python directly so nothing depends on activation, the way Python in Practice Chapter 12 taught. On and :

python3 -m venv .venv
./.venv/bin/python -m pip install -r requirements-dev.txt
./.venv/bin/python -m pytest -q

In PowerShell:

py -3 -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements-dev.txt
.\.venv\Scripts\python.exe -m pytest -q

requirements-dev.txt starts with -r requirements.txt, so it installs the runtime packages, openai, pydantic and requests at the course’s versions, plus pytest. Someone who only wants to run the program installs requirements.txt instead.

The tests pass at home exactly as they did in the sandbox. Chapter 10 wrote them with the fake client and recorded replies, so they need no network, no llm-api and no key. That is the point of writing them that way: they check your code anywhere.

Your key, on your machine only

Now set the three settings from Lesson 2, in the terminal, with your own key from your provider. Set a credit limit on the key first (Lesson 3). On macOS and Linux, export sets each one for this terminal session:

export STUDY_ASSISTANT_API_KEY=sk-or-...
export STUDY_ASSISTANT_BASE_URL=https://openrouter.ai/api/v1
export STUDY_ASSISTANT_MODEL=openai/gpt-oss-20b

In PowerShell, $env: sets each one for this window:

$env:STUDY_ASSISTANT_API_KEY = "sk-or-..."
$env:STUDY_ASSISTANT_BASE_URL = "https://openrouter.ai/api/v1"
$env:STUDY_ASSISTANT_MODEL = "openai/gpt-oss-20b"

Replace sk-or-... with your key, and keep the rules from Lesson 1: the key stays in this terminal and nowhere else. Not in a file in the project folder, not in a chat, not in a screenshot. Typed here, it lands in your shell’s history, so do this in a private session on your own machine.

Then run one live command:

./.venv/bin/python study_assistant.py ask "How do I make an independent copy of a list?"

In PowerShell, start the line with .\.venv\Scripts\python.exe instead. A real model writes its own answer, so the wording is not the course model’s, and the last line should still be Sources: 03-lists#4 or another label from the notes. Open study-assistant-log.jsonl: its last line now names openai/gpt-oss-20b, with the provider’s token count and how long the run took. To see its totals and cost estimate, run ./.venv/bin/python summarize.py.

What will differ

The scripted model’s fixed answers are gone. A live model may search with other words, read a note whole, or cite a passage it was not given, so ask may need its corrective retry, and now and then it may fail its citation check and exit 1. That is the program working: it refuses an answer it cannot back with a source. The token numbers are the provider’s own count, with the tool descriptions included, so they are higher than the course model’s for the same question.

A real model can also need more room or more time than the course model did. If the run ends with Error: The reply was cut off at the max_tokens limit. or a timeout, raise DEFAULT_MAX_TOKENS in reliable.py or CLIENT_TIMEOUT in client_calls.py a little, as Lesson 3 suggested, one at a time.

evals.py still talks to the course model at http://llm-api:8080/v1, which exists only inside this site, so at home it reports that it could not reach llm-api. stages.py calls your program’s main, so with the three variables set, its Lesson 4 block sends real requests to your provider, and without them it cannot reach the course model. Both files are for the course; the program does not need them at home.

If ask exits 1 at home, read the Error: line first: it says whether the key is missing, the provider refused the request, the network failed or timed out, the reply was cut off, or the answer was rejected. Then look at the last lines of the log, which show whether this is one bad run or the start of a pattern.

Why do the project's tests pass at home with no key and no network?

Which settings does the study assistant read from the environment when it starts?

At home, ask exits with code 1. What do you do first?