mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +00:00
From PR #6193 (FluxNimbusAi; its commit f13232ead), author kept. A client that asks the app for /v1/models got rows
without the status object, the input and output kinds and the alias rows that the engine's own list gives; a client
that decides from those fields saw a different model list through the app. Each ready instance now has a row with
status {value: "loaded"}, architecture (text, plus image when the instance has vision) and the context fields it had
before; each alias that differs from the model id is a row of its own with alias_of naming the model id.
Applies as posted (the author rebased it on the 0.2.16 layout). The PR's tests are kept: native-models-meta.test.mjs
(new) fails on the old code (it expects the alias row between the two instances' rows) and passes with the change;
native-models.test.mjs and native-models-context.test.mjs are updated to the new rows. 16 of 16 pass.
33 lines
1.9 KiB
JavaScript
33 lines
1.9 KiB
JavaScript
/** The native model list for GET /v1/models. meta.n_ctx is the context window in tokens, the key serve/server.py uses; it is left out when unknown, never 0 (#351, #3931).
|
|
* #6180: the rows mirror the rest of the engine's /v1/models shape too — a status object, architecture modalities, and one entry per alias
|
|
* (an alias row repeats its instance's entry with the id swapped and alias_of naming the canonical id), so a client that auto-detects
|
|
* through the app sees the same thing as through the engine's private port. */
|
|
const tokens = value => Number.isInteger(value) && value > 0 ? value : undefined;
|
|
|
|
export function nativeModelEntries(instances) {
|
|
const rows = [];
|
|
for (const i of instances ?? []) {
|
|
if (i.status !== 'ready') continue;
|
|
const n_ctx = tokens(i.metrics?.engine?.max_context) ?? tokens(i.context);
|
|
// #5893: also as context_length, the field OpenAI-style clients read; a client that needs the window then has no reason to use the
|
|
// engine's private port, whose key is new at every load
|
|
const entry = {
|
|
id: i.apiModelId,
|
|
object: 'model',
|
|
owned_by: 'strata',
|
|
status: { value: 'loaded' },
|
|
architecture: { input_modalities: i.vision ? ['text', 'image'] : ['text'], output_modalities: ['text'] },
|
|
...(n_ctx ? { context_length: n_ctx } : {}),
|
|
meta: { instanceId: i.id, gpus: i.gpus, label: i.label, aliases: i.aliases, ...(n_ctx ? { n_ctx } : {}) },
|
|
};
|
|
rows.push(entry);
|
|
// Alias rows mirror the engine: full entries that name their canonical id. The app's default alias is often the model tag itself,
|
|
// so an alias equal to the canonical id is skipped rather than duplicating the row.
|
|
for (const alias of i.aliases ?? []) {
|
|
if (typeof alias !== 'string' || !alias || alias === i.apiModelId) continue;
|
|
rows.push({ ...entry, id: alias, alias_of: i.apiModelId });
|
|
}
|
|
}
|
|
return rows;
|
|
}
|