M15 solution
The expected, fully-commented artifacts for M15's lab. Peek only after you've tried.
| File | What it is |
|---|---|
prepare_dataset.py |
Builds and validates a chat-format JSONL fine-tuning dataset (the part that decides quality), no key, no GPU. |
finetune.py |
The fine-tuning workflow on OpenAI's API: upload → create job → poll → use the fine-tuned model. Includes the free/local LoRA path (Hugging Face peft/unsloth) in a comment. |
Run it
python prepare_dataset.py # build + validate train.jsonl (no key needed)
# to actually fine-tune (optional, needs an OpenAI key + a few dollars):
pip install openai
python finetune.py train.jsonl # start a job → job id
python finetune.py status ftjob-... # poll until 'succeeded'
Fine-tuning here uses OpenAI (a different provider/key than Anthropic) because it offers a simple public fine-tuning API. The free alternative is local LoRA on an open model (needs a GPU).
How this was verified
Verified on Python 3 with openai 2.43.0, the API calls mocked (no key, no training cost):
- prepare_dataset.py verified for real: builds 6 examples to train.jsonl, validates every
line is well-formed chat data, and rejects a malformed line with a clear error.
- finetune.py workflow verified with a mocked OpenAI client: confirms it uploads the file with
purpose="fine-tune", creates a job against that file, retrieves status/fine_tuned_model, and
calls the fine-tuned model, matching OpenAI's documented fine-tuning API (checked against the
installed SDK's files.create / fine_tuning.jobs.create).
The actual training run needs a real key (and money/time) or a GPU for the local path, the learner's step, flagged. Dataset preparation (the core skill) runs fully offline. No key or paid call was used here.