File size: 2,080 Bytes
3eb5a0c
77b9a76
 
 
 
 
3eb5a0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Runs pairs in batches: bash scripts/batch.sh "1 2 3" task...
# Tasks on Team Tasks use harness/run-pair.ts, real-project tasks harness/run-real-pair.ts (chosen by task id).
# A pair whose two results exist without a run error is skipped, so after an interruption running this script again carries on.
# A run error (failed send, in-app browser not starting, wrong tool setup, dev server exiting…) discards the whole pair and runs it again: the old results are kept, renamed r<N>.error-<time>.json,
# 2 attempts at most by default (MAX_ATTEMPTS changes it). The ChatGPT desktop app is restarted every 10 pairs (the in-app browser stops working after long sessions).
cd "$(dirname "$0")/.."
REPS=${1:-"1 2 3"}; shift
TASKS="$*"; [ -z "$TASKS" ] && { echo "name the tasks"; exit 1; }
REAL=$(node_modules/.bin/tsx -e 'import("./tasks/real-projects.ts").then(m => console.log(m.REAL_TASKS.map(t => t.id).join(" ")))')
mkdir -p runs/logs
log() { echo "[$(date +%T)] $*"; }
ok() { for a in chatgpt mirasim; do f=runs/$a/$1/r$2.json; [ -f $f ] && ! grep -q '"error"' $f || return 1; done; }
restart() {
  pid=$(pgrep -x ChatGPT | head -1); [ -n "$pid" ] && kill -TERM $pid
  for i in $(seq 1 30); do pgrep -x ChatGPT >/dev/null || break; sleep 1; done
  for i in 1 2 3; do open -g -a /Applications/ChatGPT.app 2>/dev/null && break; sleep 5; done
  sleep 45; log "restarted ChatGPT"
}
n=0
for rep in $REPS; do for t in $TASKS; do
  ok $t $rep && continue
  [ $n -gt 0 ] && [ $((n % 10)) -eq 0 ] && restart
  runner=harness/run-pair.ts; case " $REAL " in *" $t "*) runner=harness/run-real-pair.ts;; esac
  for attempt in $(seq 1 ${MAX_ATTEMPTS:-2}); do
    log "$t r$rep (attempt $attempt)"
    node_modules/.bin/tsx $runner --task $t --rep $rep > runs/logs/$t-r$rep.log 2>&1
    grep -E '"(arm|pass|duration_s|model_requests|error)"' runs/logs/$t-r$rep.log | paste -sd' ' -
    ok $t $rep && break
    for a in chatgpt mirasim; do f=runs/$a/$t/r$rep.json; [ -f $f ] && mv $f ${f%.json}.error-$(date +%s).json; done
    restart
  done
  n=$((n+1))
done; done
log "all done"