Running the labs¶
Every lab is one TypeScript file in the labs folder, split into numbered steps. You run steps from the terminal and read the code in your editor, side by side.
| Lab | File | Run it with |
|---|---|---|
| Setup check | labs/00-setup-check.ts |
npm run lab0 |
| Lab 1 | labs/01-first-multimodal-calls.ts |
npm run lab1 |
| Lab 2 | labs/02-invoices-and-charts.ts |
npm run lab2 |
| Lab 3 | labs/03-audio-to-minutes.ts |
npm run lab3 |
| Lab 4 | labs/04-search-and-rag.ts |
npm run lab4 |
| Lab 5 | labs/05-safety-and-evaluation.ts |
npm run lab5 |
| Capstone | labs/06-capstone.ts |
npm run capstone |
The three commands you need¶
| To do this | Type |
|---|---|
| Run every step of Lab 2, in order | npm run lab2 |
| Run only Step 4 | npm run lab2 -- 4 |
| Run Steps 2 to 4 | npm run lab2 -- 2-4 |
The two dashes (--) pass the step number to the lab. Each step prints a header like this, so you always know where you are:
──────────────────────────────────────────────────────────────────────
Step 4 · Find what the model got wrong
──────────────────────────────────────────────────────────────────────
Press Ctrl + C to stop a step that takes too long.
Saved answers make re-runs free¶
Some steps use results from earlier steps (Step 3 checks the invoice that Step 2 read). The lab simply repeats the earlier call, and the helper reuses the saved answer from data/_cache. You'll see:
A real call prints the time and tokens instead:
That's the provider, the time taken, and the tokens sent and received.
Info
Want a fresh answer? Change the prompt (any change makes a new request), delete the data/_cache folder, or set LLM_CACHE=0 in .env.
Looking at images¶
Steps that use an image print its full path, for example:
In VS Code, Ctrl + click (Mac: Cmd + click) the path to open the image next to your terminal.
Adding your own step ("Your turn")¶
Each lab ends with a comment that marks where your steps go. Add a new numbered step in the same shape as the others:
8: {
title: "My test: a blurry invoice", run: async () => {
const inv = await askJson(PROMPT, { images: ["data/my_invoice.jpg"], schema: Invoice });
console.log(validate(inv));
},
},
Save the file, then run npm run lab2 -- 8. You don't need to compile anything: tsx runs TypeScript directly.
Trying something quickly: the playground¶
To test a prompt on any file without editing a lab:
npm run play -- "What is on this page?" data/whiteboard.png
npm run play -- "Return the invoice number and total as JSON" data/invoice_01.png --json
Good habits¶
- Run
npm run lab0again if anything feels broken: it checks your key and files. - After you edit
.env, just run the step again. There's nothing to restart. - Keep the lab file open in your editor while you run it. The code is short on purpose; read it.