Skip to content

M6 solution

The expected, fully-commented artifacts for M6's lab. Peek only after you've tried the lab.

File What it is
parameters.py max_tokens (length cap) and temperature (randomness) on claude-haiku-4-5, with the explanation of why temperature isn't used on the newest Opus models.
streaming.py client.messages.stream(...) printing a reply word-by-word via text_stream.
extract.py The build: guaranteed structured JSON via output_config + a schema, parsed into a dict with json.loads (no defensive parsing).

Run it

With your venv active and your M4 .env (key) in the folder:

python parameters.py     # max_tokens + temperature
python streaming.py      # word-by-word output
python extract.py        # describe an expense; get back structured fields

How this was verified

Verified on Python 3 with anthropic 0.109.2 + python-dotenv, with the live model call mocked (no key or billed call used). First the installed SDK was introspected to confirm it supports output_config, messages.parse, messages.stream, and temperature. Then: - all files compile; - extract.py sends output_config with the JSON schema and parses the (guaranteed) JSON into the printed fields; - parameters.py sends temperature (0.0 and 1.0) and max_tokens (15, 20, 80) to claude-haiku-4-5; - streaming.py consumes text_stream chunk-by-chunk.

The only thing a real key adds is the actual model wording (and the visible temperature variety), that's the learner's live run, and the one item flagged for a human pilot.