pi-c  Artifact [adbc623c45]

Artifact adbc623c453d45672b750f1251d5e00d038de8d0ed13638b151c793ee118a3bf:

  • File src/models.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: 2473) [annotate] [blame] [check-ins using] [more...]


/* Model registry: which provider, wire API, endpoint and credential a model
 * name means. Names are "provider/model" as in Pi; built-in providers carry
 * Pi's base URLs, APIs and key variables, and ~/.pic/models.json (or Pi's
 * ~/.pi/agent/models.json) adds or overrides providers and models. */
#ifndef PIC_MODELS_H
#define PIC_MODELS_H

#include <stddef.h>

typedef enum { PIC_API_ANTHROPIC, PIC_API_CHAT, PIC_API_RESPONSES } pic_api;

/* openai-completions dialect switches, named after Pi's compat flags. */
typedef struct {
    int supports_store;              /* send store:false */
    int supports_developer_role;     /* developer role for reasoning models */
    int supports_usage_in_streaming; /* stream_options.include_usage */
    int supports_reasoning_effort;   /* send reasoning_effort */
    int max_tokens_field_legacy;     /* max_tokens instead of max_completion_tokens */
    int requires_reasoning_content;  /* empty reasoning_content on replayed turns (DeepSeek) */
    int anthropic_cache_control;     /* OpenRouter anthropic/... models take cache_control */
    char thinking_format[24];        /* openai, openrouter, deepseek, zai, qwen, together */
} pic_compat;

typedef struct {
    char provider[64];
    char id[192];       /* the model id sent on the wire */
    pic_api api;
    char base_url[256]; /* without a trailing slash */
    char key_env[64];   /* variable holding the key; "" means no key */
    char key_literal[256]; /* a key written into models.json, if that is how it was given */
    char headers[1024]; /* extra "Name: value" lines, '\n' separated */
    int reasoning;
    long context_window, max_tokens;
    pic_compat compat;
} pic_model;

/* Resolves NAME ("provider/model", or a bare built-in model id) using the
 * built-in table and the user's models file. 0, or -1 with err. */
int pic_model_resolve(const char *name, pic_model *out, char *err, size_t errcap);
const char *pic_api_name(pic_api api);
/* The request URL for a model: base URL plus the API's path. */
void pic_model_url(const pic_model *m, char *out, size_t cap);
/* Whether PROVIDER has a key configured (its variable set, or a key in the
 * models file), or needs none: Pi shows only these in its model picker. */
int pic_model_available(const char *provider);
/* Calls fn for each model the models file defines (providers.*.models[]). */
int pic_models_each_user(int (*fn)(void *ctx, const char *provider, const char *json), void *ctx);

#endif