scripts: add s/optimize — LLM prompt optimization pipeline

Generates N candidate optimized prompts in parallel, then judges and
returns the best. Accepts -cb/-cm for candidate model and -jb/-jm for
judge model, defaulting to OLLIE_BACKEND/OLLIE_MODEL for both stages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-04-18 11:28:54 +02:00
parent a69f1cbc2b
commit fc818dd28f
3 changed files with 71 additions and 1 deletions

2
9p

@ -1 +1 @@
Subproject commit 3a96284d986478fbac63d3b25edcbbe3b16cfdc8
Subproject commit 5bb1783808a91ed58c322791876b02d3ee4417e8

1
mkfile
View File

@ -45,6 +45,7 @@ scripts:V:
cp -f scripts/oq-schedule $HOME/.config/ollie/scripts/sched
cp -f scripts/ls $HOME/.config/ollie/scripts/ls
cp -f scripts/kill $HOME/.config/ollie/scripts/kill
cp -f scripts/optimize $HOME/.config/ollie/scripts/optimize
help:V:
echo 'Ollie monorepo build targets:'

69
scripts/optimize Normal file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bash
# s/optimize: generate N candidate optimized prompts and select the best.
set -euo pipefail
for _arg; do
[ "$_arg" = "-help" ] && cat <<'EOF' && exit 0
usage: optimize [flags] [prompt...]
echo "prompt" | optimize [flags]
Generates N optimized candidates for a prompt, then judges and returns the best.
Uses OLLIE_MODEL and OLLIE_BACKEND by default for both stages.
Flags:
-n N number of candidates to generate (default: 3)
-cb BACKEND candidate generation backend
-cm MODEL candidate generation model
-jb BACKEND judge backend
-jm MODEL judge model
-help show this help
EOF
done
n=3; cb=; cm=; jb=; jm=
while [ $# -gt 0 ]; do
case $1 in
-n) n=$2; shift ;;
-cb) cb=$2; shift ;;
-cm) cm=$2; shift ;;
-jb) jb=$2; shift ;;
-jm) jm=$2; shift ;;
-help) ;;
--) shift; break ;;
-*) printf 'optimize: unknown flag: %s\n' "$1" >&2; exit 1 ;;
*) break ;;
esac
shift
done
if [ $# -gt 0 ]; then
prompt="$*"
elif ! [ -t 0 ]; then
prompt=$(cat)
else
printf 'optimize: prompt required\n' >&2; exit 1
fi
[ -z "$prompt" ] && { printf 'optimize: empty prompt\n' >&2; exit 1; }
Q="${0%/*}/q"
c_flags=()
j_flags=()
[ -n "$cb" ] && c_flags+=(-backend "$cb")
[ -n "$cm" ] && c_flags+=(-model "$cm")
[ -n "$jb" ] && j_flags+=(-backend "$jb")
[ -n "$jm" ] && j_flags+=(-model "$jm")
printf 'generating %d candidates...\n' "$n" >&2
candidates=$("$Q" "${c_flags[@]}" -parallel "$n" \
"Optimize the following prompt. Return only the optimized prompt, no explanation or preamble:
$prompt")
printf 'judging...\n' >&2
"$Q" "${j_flags[@]}" \
"Review these candidate prompts and return only the single best one, no explanation or preamble:
$candidates"