Artifact d624f3f1991f9451068c3d86f321a27c05361f56aa1a8c4ee3653c64e5799848:
- File
tools/model-catalog.sh
— part of check-in
[998e8169f1]
at
2026-11-19 15:39:12
on branch thinking
— Thinking levels as in Pi, for every API
Pi's levels (off, minimal, low, medium, high, xhigh, max) limited to what each model supports per Pi's catalog (thinkingLevelMap, now in the built-in snapshot), and sent as Pi sends them: Anthropic adaptive thinking with effort for models that force it, otherwise thinking budgets with max_tokens raised, disabled when off; Chat Completions by thinking format (reasoning_effort, OpenRouter reasoning, DeepSeek and Z.ai thinking, Qwen and Together switches); Responses reasoning.effort. The level comes from --thinking, else the saved per-model or default level, else medium; pic models --thinking-default saves the default and pic models --json lists each model's levels. agent_start reports the level. (user: dmestas, size: 2991) [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, thinkingLevelMap). 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(CASE WHEN json_type(v,'\$.thinkingLevelMap') IS NULL THEN obj ELSE json_insert(obj, '\$.thinkingLevelMap', json(json_extract(v,'\$.thinkingLevelMap'))) END, '\\', '\\\\'), '\"', '\\\"') || '\"},' FROM (SELECT provider, v, 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'), '{}'))) AS obj 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"