#!/bin/bash
export LC_ALL=C
DB=/root/.9router/db/data.sqlite
KEY=$(python3 - "$DB" <<'PY'
import sqlite3,sys
c=sqlite3.connect(sys.argv[1])
cols=[r[1] for r in c.execute("pragma table_info(apiKeys)")]
r=c.execute("select * from apiKeys limit 1").fetchone()
print(r[cols.index('key')])
PY
)

echo "===== MODEL LIST ====="
curl -s --max-time 10 -H "Authorization: Bearer $KEY" http://127.0.0.1:20128/v1/models -o /tmp/models.json -w 'http=%{http_code}\n'
python3 - <<'PY'
import json
try:
    d=json.load(open('/tmp/models.json'))
except Exception as e:
    print("parse err",e); raise SystemExit
data=d.get('data',d if isinstance(d,list) else [])
print("  total models:", len(data))
ids=[m.get('id') for m in data if isinstance(m,dict)]
for i in sorted(ids):
    print("   ", i)
PY

echo
echo "===== LATENCY: candidate models (2 runs each) ====="
for m in mimo-code opencode/deepseek-v4-flash opencode/deepseek-flash deepseek/deepseek-v4-flash; do
  printf '  %-32s ' "$m"
  for run in 1 2; do
    t=$(curl -s -o /tmp/r.json -w '%{http_code}/%{time_total}' --max-time 60 -X POST \
      http://127.0.0.1:20128/v1/chat/completions \
      -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
      -d "{\"model\":\"$m\",\"messages\":[{\"role\":\"user\",\"content\":\"say hi\"}],\"max_tokens\":8}" 2>/dev/null)
    printf '%s  ' "$t"
  done
  echo
done
