providers: models= keeps a provider's served list to the local models

A provider block may name the only models it offers (a bracket list in
the block syntax). sp_provider_served() then filters the endpoint's
/v1/models, so --model-list and /model's probe show only those ids.
The n95 junction provider uses it for qwen3.6-35b-checked,
qwen3.6-35b and qwen3.8-27b, not the cloud models junction also serves.
This commit is contained in:
Konrad Lother committed 2026-11-20 06:57:11 +00:00
1 parent 37d038f716
commit 5fd8f76870
7 files changed
+40

No files matched your search

+6
View File
@@ -386,6 +386,12 @@ do_provider(struct cb *c, const char *name, unsigned line, struct ent *e,
goto done;
if (list[0] != '\0')
sp_buf_printf(&l, " | tags=%s", list);
} else if (!strcmp(k, "models")) {
joined(&e[i].v, list, sizeof(list));
if (!clean(c, &e[i], list))
goto done;
if (list[0] != '\0')
sp_buf_printf(&l, " | models=%s", list);
} else if (!strcmp(k, "key")) {
/* the key itself, in the (0600) file: kept in a private
* variable that key_env then names */
+2
View File
@@ -289,6 +289,8 @@ parse_delegate(struct sp_delegate *d, const char *val, struct sp_buf *err,
snprintf(d->endpoint, sizeof(d->endpoint), "%s", s + 9);
else if (!strncmp(s, "model=", 6))
snprintf(d->model, sizeof(d->model), "%s", s + 6);
else if (!strncmp(s, "models=", 7))
snprintf(d->models, sizeof(d->models), "%s", s + 7);
else if (!strncmp(s, "key_env=", 8))
snprintf(d->key_env, sizeof(d->key_env), "%s", s + 8);
else if (!strncmp(s, "ctx=", 4)) {
+1
View File
@@ -77,6 +77,7 @@ struct sp_delegate {
char tags[128]; /* comma separated, matched against the task */
char endpoint[512];
char model[256];
char models[512]; /* optional comma list: the only models this provider offers */
char key_env[64];
unsigned long ctx; /* context window in tokens, 0 = unknown */
char env[SP_CONFIG_MAX_ENV][SP_CONFIG_ENV_LEN]; /* NAME=VALUE */
+1
View File
@@ -159,6 +159,7 @@ tool_delegate_list(const char *args, struct sp_buf *out, void *ctx)
snprintf(pv.endpoint, sizeof(pv.endpoint), "%s",
d->endpoint);
snprintf(pv.model, sizeof(pv.model), "%s", d->model);
snprintf(pv.models, sizeof(pv.models), "%s", d->models);
snprintf(pv.key_env, sizeof(pv.key_env), "%s",
d->key_env);
/* a literal key lives in 'key' until the child starts */
+27
View File
@@ -96,6 +96,7 @@ delegates:
snprintf(out->kind, sizeof(out->kind), "%s", d->kind);
snprintf(out->endpoint, sizeof(out->endpoint), "%s", d->endpoint);
snprintf(out->model, sizeof(out->model), "%s", d->model);
snprintf(out->models, sizeof(out->models), "%s", d->models);
snprintf(out->key_env, sizeof(out->key_env), "%s", d->key_env);
snprintf(out->key, sizeof(out->key), "%s", d->key);
snprintf(out->about, sizeof(out->about), "%s", d->about);
@@ -447,6 +448,30 @@ provider_headers(const struct sp_provider *p, char *hdr, size_t cap,
return n;
}
/* 1 when the provider's optional models= list is empty or names this id */
static int
provider_lists(const struct sp_provider *p, const char *id)
{
char list[512], *tok, *save = NULL;
if (p->models[0] == '\0')
return 1;
snprintf(list, sizeof(list), "%s", p->models);
for (tok = strtok_r(list, ",", &save); tok != NULL;
tok = strtok_r(NULL, ",", &save)) {
char *end;
while (*tok == ' ' || *tok == '\t')
tok++;
end = tok + strlen(tok);
while (end > tok && (end[-1] == ' ' || end[-1] == '\t'))
*--end = '\0';
if (*tok != '\0' && strcmp(tok, id) == 0)
return 1;
}
return 0;
}
int
sp_provider_served(const struct sp_provider *p, struct sp_buf *ids,
struct sp_buf *err)
@@ -483,6 +508,8 @@ sp_provider_served(const struct sp_provider *p, struct sp_buf *ids,
if (id == NULL)
continue;
if (!provider_lists(p, id))
continue;
if (ids->len > 0 && sp_buf_puts(ids, "\n") != 0)
goto oom;
if (sp_buf_puts(ids, id) != 0)
+1
View File
@@ -22,6 +22,7 @@ struct sp_provider {
char kind[16]; /* "openai" (default), "anthropic" or "cli" */
char endpoint[512];
char model[256];
char models[512]; /* optional comma list, filters what the endpoint serves */
char key_env[64];
char key[256]; /* a literal key (d->key), wins over key_env */
char about[128];
+2
View File
@@ -783,6 +783,7 @@ run_doctor(const struct sp_config *conf, const struct opts *o)
snprintf(pv.kind, sizeof(pv.kind), "%s", d->kind);
snprintf(pv.endpoint, sizeof(pv.endpoint), "%s", d->endpoint);
snprintf(pv.model, sizeof(pv.model), "%s", d->model);
snprintf(pv.models, sizeof(pv.models), "%s", d->models);
snprintf(pv.key_env, sizeof(pv.key_env), "%s", d->key_env);
/* the model list only: never a completion, never a token spent */
if (sp_buf_init(&ids) == 0 && sp_buf_init(&perr) == 0) {
@@ -988,6 +989,7 @@ run_model_list(const struct sp_config *conf, const struct opts *o)
snprintf(pv.kind, sizeof(pv.kind), "%s", d->kind);
snprintf(pv.endpoint, sizeof(pv.endpoint), "%s", d->endpoint);
snprintf(pv.model, sizeof(pv.model), "%s", d->model);
snprintf(pv.models, sizeof(pv.models), "%s", d->models);
snprintf(pv.key_env, sizeof(pv.key_env), "%s", d->key_env);
served = sp_provider_served(&pv, &ids, &perr) == 0;
}