Artifact e5a030cd7240a93fa02e522802818ebddd126aa58915b4772427109ef2ced382:
- File
tools/model-catalog.sh
— part of check-in
[1011fc8472]
at
2026-11-19 23:29:07
on branch gemini
— A Google Gemini provider, as Pi's
The google-generative-ai API: streamGenerateContent over SSE with GEMINI_API_KEY, native parts replayed per conversation, tool calls and results, usage, and Pi's thinking mapping (thinkingLevel for Gemini 3 and later, a token budget for 2.5, 0 for off). A conversation can move between Gemini and the other providers turn by turn. Recorded streams cover text, thinking, tools, parallel calls, safety blocks, truncation and errors. (user: dmestas, size: 3023) [annotate] [blame] [check-ins using]
#!/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','google') AND json_extract(x.value,'\$.type') = 'chat' AND json_extract(x.value,'\$.api') IN ('anthropic-messages','openai-completions','openai-responses','google-generative-ai')) 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"