#!/usr/bin/env bash
# Real demos for P188 "RAG vs Fine-Tuning: Which One Should You Use?".
# One real Google Colab T4 GPU (15 GB), driven from the Mac with Google's colab CLI (~/.venvs/colab, signed in).
# lab/helpbot/ is uploaded to the GPU machine and lab/helpbot/run_lab.py runs every command of the video there, in
# order, in that folder: the same small open model (Qwen2.5-1.5B-Instruct) answers a help desk's questions three ways:
#   base        the model alone (ask.py, quiz.py base)
#   RAG         index.py embeds each paragraph of docs/ (all-MiniLM-L6-v2); ask.py --rag pastes the two closest into the prompt
#   fine-tuned  finetune.py trains LoRA weights on train.jsonl (108 question/answer pairs, make_train.py); ask.py --tuned
# then the restocking fee in docs/returns.md is edited (12% -> 8%) and all three are asked again, alone and together.
# quiz.py asks ten held-out questions (worded differently from the training questions) and checks each answer for the
# fact as docs/ states it. Greedy decoding, fixed seeds: three full runs gave the same answers and scores.
# Output: lab/raw_output.json (stderr and timings too) and demo_output.json. About 7 minutes of T4.
set -euo pipefail
cd "$(dirname "$0")"
python3 lab/colab_lab.py start
until python3 lab/colab_lab.py poll 400 | grep -q "LAB DONE\|STOPPED"; do sleep 20; done
python3 lab/colab_lab.py fetch
python3 lab/colab_lab.py stop
