M4 solution
The expected, fully-commented artifacts for M4's lab. Peek only after you've tried the lab.
| File | What it is |
|---|---|
check_setup.py |
The smallest possible call, loads .env, validates the key, makes one tiny request. Run this first. |
chatbot.py |
The minimal chatbot: a system personality, a running messages list, and a loop that remembers the conversation. |
.env.example |
Template for your secret key. Copy to .env (which is git-ignored) and paste your real key. Never commit .env. |
Run it
On your own machine, with your virtual environment active and your key in .env:
pip install anthropic python-dotenv # once (or: pip install -r ../../requirements.txt)
python check_setup.py # confirm the key works
python chatbot.py # chat (type 'quit' to leave)
How this was verified
Everything except the live billed call was verified on Python 3 with anthropic 0.109.2 and
python-dotenv in a fresh virtual environment:
- all three files compile;
- python-dotenv loads a placeholder key from .env and anthropic.Anthropic() constructs against it;
- the chatbot loop was exercised end-to-end with the API mocked: it sends model,
system, and the growing messages list, reads response.content[0].text, and appends the
reply so the bot remembers.
The single thing only a real key can confirm is the live response text, that's the learner's
Step 6 (check_setup.py), and it's the one item flagged for a human pilot. No real API key or
billed call was used in preparing this module.