Artifact b55133aaf3bcbe3c7b2bbe5534b0c3da0868925fd834aefc0bde4aeaff65d105:
- File
src/catalog.h
— 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: 1557) [annotate] [blame] [check-ins using] [more...]
/* The model catalog (catalog.c): Pi's catalog of models for pic's providers, * as Pi keeps it. A snapshot is built in (model_catalog.inc); fresher * per-provider lists from https://pi.dev/api/models/providers/<id> are kept in * ~/.pic/models-store.json and used when newer than the snapshot. Entries * are Pi model objects (JSON: id, name, api, baseUrl, reasoning, * contextWindow, maxTokens, compat). */ #ifndef PIC_CATALOG_H #define PIC_CATALOG_H #include <stddef.h> /* The model object for provider/id (malloc'd JSON), or NULL. */ char *pic_catalog_find(const char *provider, const char *id); /* Calls fn for each model of the catalog, provider by provider; stops when * fn returns non-zero. 0, or -1 when the store could not be read. */ int pic_catalog_each(int (*fn)(void *ctx, const char *provider, const char *json), void *ctx); /* Refreshes the stored lists from pi.dev: each built-in provider not checked * in the last 4 hours (all of them when force), with If-None-Match. Offline * or failing providers keep what is stored. PIC_MODEL_CATALOG=offline turns * fetching off. 0 when every provider was fresh or refreshed; -1 with err * naming the first failure otherwise. */ int pic_catalog_refresh(int force, char *err, size_t errcap); /* Shared by catalog.c and catalog_fetch.c. */ #define PIC_CATALOG_NPROVIDERS 13 extern const char *const pic_catalog_providers[PIC_CATALOG_NPROVIDERS]; int pic_catalog_store_path(char *out, size_t cap, int make_dir); char *pic_catalog_read_store(void); /* the store, or "{}" (malloc'd) */ #endif