#!/usr/bin/env bash
# Real demos for P184 "How RAG Works". Made on the Mac (Docker Desktop, CPU only).
# Kari runs a small hardware store; its help desk answers customers with a language model. Two containers on one lab
# network: the official ollama/ollama image with nomic-embed-text (embeddings) and llama3.2:3b (answers), and the
# help desk computer (lab/Dockerfile: python:3.12-slim, the store's five documents and lab/helpdesk.py, standard
# library only). Kari types every command into one real interactive bash in a pty (demo_driver.py); the one document
# edit (a holiday returns rule) is made off screen, as she would in an editor. Every line in video.json is read from
# demo_output.json.
set -euo pipefail
cd "$(dirname "$0")"
N=ce-p184 O=ce-p184-ollama H=ce-p184-shop
cleanup() { docker rm -f $H $O >/dev/null 2>&1 || true; docker network rm $N >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker network create $N >/dev/null
docker run -d --name $O --network $N --network-alias ollama -v ce-p184-models:/root/.ollama ollama/ollama >/dev/null
for i in $(seq 30); do docker exec $O ollama list >/dev/null 2>&1 && break; sleep 1; done
pull() { for t in 1 2 3 4; do docker exec $O ollama pull "$1" >/dev/null 2>&1 && return; sleep 10; done; echo "pull $1 failed" >&2; exit 1; }
pull nomic-embed-text
pull llama3.2:3b
docker build -q -t ce-p184 lab >/dev/null
docker run -d --name $H --hostname shop --network $N ce-p184 sleep infinity >/dev/null
python3 demo_driver.py "$H" "$O"
