Artifact e94c24beb42a4a08d41572c3a6ce8310d856056ebb4b41925926a2852529dd09:
- File
tools/model-catalog.sh
— part of check-in
[fb82c37817]
at
2026-11-19 14:01:47
on branch models
— Model picker, slash command menu and Pi's model catalog
Models are chosen as in Pi. pic carries a snapshot of Pi's catalog for its providers (653 chat models; tools/model-catalog.sh regenerates it from pi.dev/api/models) and lays fresher per-provider lists from pi.dev over it, cached in ~/.pic/models-store.json with ETags and trusted for four hours, used only when newer than the snapshot. Resolution takes a model's API, endpoint, limits and compat settings from the catalog before the models file. pic models lists the models of providers with a key (--all every one, --json, --refresh); pic models --default saves the model used when none is given.
In the terminal interface, Ctrl+L or /model opens a picker of the models whose provider has a key, filtered by Pi's fuzzy matching as you type, current and default first; Enter uses the model, Ctrl+S also saves it as the default; Ctrl+P cycles. Typing / shows a menu of commands with their arguments (Tab completes, Enter runs) and /model completes model names. New commands show the conversation's details and token counts, copy the last reply (OSC 52 and the system clipboard), export, clone and list the hotkeys. (user: dmestas, size: 2716) [annotate] [blame] [check-ins using] [more...]
#!/bin/sh # Regenerates src/model_catalog.inc, pic's built-in snapshot of Pi's model # catalog (https://pi.dev/api/models), for the providers and APIs pic has: # one row per chat model with its Pi model object (id, name, api, baseUrl, # reasoning, contextWindow, maxTokens, compat). At run time pic lays # fresher per-provider data from the same service over it # (~/.pic/models-store.json), as Pi does. Needs curl and sqlite3. # Usage: sh tools/model-catalog.sh [CATALOG_JSON] (fetches when not given) set -eu cd "$(dirname "$0")/.." tmp=$(mktemp -d "${TMPDIR:-/tmp}/pic-catalog.XXXXXX") trap 'rm -rf -- "$tmp"' EXIT HUP INT TERM if [ $# -ge 1 ]; then cp "$1" "$tmp/all.json" else curl -fsS -m 60 -A 'pic-catalog' -o "$tmp/all.json" 'https://pi.dev/api/models?types=chat' fi now=$(($(date +%s) * 1000)) out=src/model_catalog.inc { printf '/* Generated by tools/model-catalog.sh from Pi'"'"'s model catalog (https://pi.dev/api/models)\n' printf ' * on %s. Do not edit: regenerate. */\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" printf '#define PIC_CATALOG_GENERATED_MS %sLL\n' "$now" printf 'static const struct {\n const char *provider, *id, *json;\n} catalog_snapshot[] = {\n' sqlite3 :memory: " WITH d(j) AS (SELECT readfile('$tmp/all.json')), m AS (SELECT p.key AS provider, x.value AS v FROM d, json_each(d.j) p, json_each(p.value) x WHERE p.key IN ('anthropic','openai','openrouter','xai','groq','cerebras','deepseek','together', 'fireworks','huggingface','nvidia','moonshotai','zai') AND json_extract(x.value,'\$.type') = 'chat' AND json_extract(x.value,'\$.api') IN ('anthropic-messages','openai-completions','openai-responses')) SELECT ' {\"' || provider || '\", \"' || replace(json_extract(v,'\$.id'), '\"', '\\\"') || '\", \"' || replace(replace(json_object('id', json_extract(v,'\$.id'), 'name', json_extract(v,'\$.name'), 'api', json_extract(v,'\$.api'), 'baseUrl', json_extract(v,'\$.baseUrl'), 'reasoning', json(CASE WHEN json_extract(v,'\$.reasoning') THEN 'true' ELSE 'false' END), 'contextWindow', json_extract(v,'\$.contextWindow'), 'maxTokens', json_extract(v,'\$.maxTokens'), 'compat', json(coalesce(json_extract(v,'\$.compat'), '{}'))), '\\', '\\\\'), '\"', '\\\"') || '\"},' FROM m ORDER BY provider, json_extract(v,'\$.id')" printf '};\n' } > "$tmp/out" n=$(grep -c '^ {"' "$tmp/out") [ "$n" -gt 100 ] || { echo "model-catalog: only $n models; refusing to write $out" >&2; exit 1; } mv "$tmp/out" "$out" printf 'model-catalog: %s models written to %s\n' "$n" "$out"