mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +00:00
control app: native /v1/models rows mirror status, architecture and aliases (#6180)
This commit is contained in:
1 parent
58ee322772
commit
f13232ead9
4 files changed
+115
-10
No files matched your search
@@ -1,11 +1,32 @@
|
||||
/** 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). */
|
||||
/** 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) {
|
||||
return (instances ?? []).filter(i => i.status === 'ready').map(i => {
|
||||
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
|
||||
return { id: i.apiModelId, object: 'model', owned_by: 'strata', ...(n_ctx ? { context_length: n_ctx } : {}), meta: { instanceId: i.id, gpus: i.gpus, label: i.label, aliases: i.aliases, ...(n_ctx ? { n_ctx } : {}) } };
|
||||
});
|
||||
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;
|
||||
}
|
||||
@@ -15,8 +15,8 @@ const instances = [
|
||||
|
||||
test('ready models carry their window as context_length and meta.n_ctx; an unknown window is left out', () => {
|
||||
const list = nativeModelEntries(instances);
|
||||
assert.deepEqual(list.map(m => m.id), ['qwen3.8-flash-next', 'configured-only', 'unknown-window'], 'a model still loading is not listed');
|
||||
const [live, configured, unknown] = list;
|
||||
assert.deepEqual(list.map(m => m.id), ['qwen3.8-flash-next', 'local', 'configured-only', 'unknown-window'], 'a model still loading is not listed; the alias of the ready model rides along as its own row (#6180)');
|
||||
const [live, , configured, unknown] = list;
|
||||
assert.equal(live.context_length, 120000, 'the engine\'s live window first');
|
||||
assert.equal(live.meta.n_ctx, 120000);
|
||||
assert.equal(configured.context_length, 65536);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/* #6180: the native /v1/models route must mirror the engine's metadata —
|
||||
* meta.n_ctx, status, architecture, and alias entries — so OpenAI-compatible
|
||||
* clients can auto-detect the context window instead of guessing it. */
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { nativeModelEntries } from '../server/native-models.mjs';
|
||||
|
||||
// One ready native instance exactly as native-control's state() reports it:
|
||||
// metrics from the engine's /metrics (engine.max_context), vision on,
|
||||
// two aliases of which one is the model tag itself.
|
||||
function instance(over = {}) {
|
||||
return {
|
||||
id: 'e02a266a-1111-2222-3333-444455556666',
|
||||
apiModelId: 'swift-iq3_s',
|
||||
model: 'swift-1.5-iq3_s',
|
||||
label: 'Swift 1.5 IQ3_S',
|
||||
context: 262144,
|
||||
gpus: [1],
|
||||
vision: true,
|
||||
aliases: ['Strata', 'swift-iq3_s'],
|
||||
status: 'ready',
|
||||
loadedAt: '2026-11-17T22:27:55Z',
|
||||
metrics: { engine: { max_context: 262144 }, live: { state: 'idle' } },
|
||||
...over,
|
||||
};
|
||||
}
|
||||
|
||||
test('native /v1/models rows carry the engine-side truth (#6180)', () => {
|
||||
const rows = nativeModelEntries([instance()]);
|
||||
const canonical = rows.find(r => r.id === 'swift-iq3_s');
|
||||
assert.ok(canonical, 'the canonical apiModelId row exists');
|
||||
assert.equal(canonical.alias_of, undefined, 'the canonical row is not an alias of anything');
|
||||
assert.deepEqual(canonical.status, { value: 'loaded' });
|
||||
assert.deepEqual(canonical.architecture, { input_modalities: ['text', 'image'], output_modalities: ['text'] });
|
||||
assert.equal(canonical.meta.n_ctx, 262144, 'n_ctx is the engine window, not a guess');
|
||||
assert.equal(canonical.meta.instanceId, 'e02a266a-1111-2222-3333-444455556666');
|
||||
assert.deepEqual(canonical.meta.gpus, [1]);
|
||||
assert.equal(canonical.meta.label, 'Swift 1.5 IQ3_S');
|
||||
assert.deepEqual(canonical.meta.aliases, ['Strata', 'swift-iq3_s']);
|
||||
});
|
||||
|
||||
test('alias entries are full rows with alias_of; the canonical tag alias does not duplicate', () => {
|
||||
const rows = nativeModelEntries([instance()]);
|
||||
const ids = rows.map(r => r.id);
|
||||
assert.deepEqual(ids, ['swift-iq3_s', 'Strata'], 'only the distinct alias is added');
|
||||
const alias = rows.find(r => r.id === 'Strata');
|
||||
assert.equal(alias.alias_of, 'swift-iq3_s');
|
||||
assert.equal(alias.meta.n_ctx, 262144, 'alias rows mirror the engine: same full entry');
|
||||
assert.deepEqual(alias.architecture, { input_modalities: ['text', 'image'], output_modalities: ['text'] });
|
||||
});
|
||||
|
||||
test('n_ctx falls back to the load-time context, and is omitted when neither is known', () => {
|
||||
const noMetrics = nativeModelEntries([instance({ metrics: undefined })]);
|
||||
assert.equal(noMetrics[0].meta.n_ctx, 262144, 'context field covers a metrics gap');
|
||||
const blind = nativeModelEntries([instance({ metrics: undefined, context: undefined })]);
|
||||
assert.equal('n_ctx' in blind[0].meta, false, 'no number is invented when the window is unknown');
|
||||
});
|
||||
|
||||
test('a text-only model advertises text input only', () => {
|
||||
const rows = nativeModelEntries([instance({ vision: false, aliases: [] })]);
|
||||
assert.equal(rows.length, 1, 'no aliases means exactly one row');
|
||||
assert.deepEqual(rows[0].architecture.input_modalities, ['text']);
|
||||
});
|
||||
|
||||
test('every ready instance gets its own rows', () => {
|
||||
const rows = nativeModelEntries([
|
||||
instance({ id: 'one', apiModelId: 'swift-iq3_s', aliases: ['Strata'] }),
|
||||
instance({ id: 'two', apiModelId: 'qwen-iq2_xs', model: 'qwen', label: 'Qwen', vision: false, aliases: [], metrics: { engine: { max_context: 32768 } }, context: 32768 }),
|
||||
]);
|
||||
assert.deepEqual(rows.map(r => r.id), ['swift-iq3_s', 'Strata', 'qwen-iq2_xs']);
|
||||
assert.equal(rows.find(r => r.id === 'qwen-iq2_xs').meta.n_ctx, 32768);
|
||||
});
|
||||
|
||||
test('the native route in index.mjs uses nativeModelEntries instead of the stripped map', async () => {
|
||||
const src = await readFile(fileURLToPath(new URL('../server/index.mjs', import.meta.url)), 'utf8');
|
||||
const route = src.split('\n').find(l => l.includes("if(path==='/v1/models'&&method==='GET')"));
|
||||
assert.ok(route, 'the native /v1/models route line is found');
|
||||
assert.match(route, /nativeModelEntries/, 'the route delegates to the shared mapper');
|
||||
assert.doesNotMatch(route, /owned_by:'strata',meta:\{instanceId/, 'the old inline stripped map is gone');
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { nativeModelEntries } from '../server/native-models.mjs';
|
||||
const ready = (patch = {}) => ({ id: 'inst-a', apiModelId: 'qwen-q2_0', status: 'ready', gpus: [0], label: 'Qwen 3.6', aliases: ['qwen-q2_0'], context: 65536, metrics: null, ...patch });
|
||||
|
||||
test('the configured context is reported as n_ctx and the other keys are unchanged', () => {
|
||||
assert.deepEqual(nativeModelEntries([ready()]), [{ id: 'qwen-q2_0', object: 'model', owned_by: 'strata', context_length: 65536, meta: { instanceId: 'inst-a', gpus: [0], label: 'Qwen 3.6', aliases: ['qwen-q2_0'], n_ctx: 65536 } }]);
|
||||
assert.deepEqual(nativeModelEntries([ready()]), [{ id: 'qwen-q2_0', object: 'model', owned_by: 'strata', status: { value: 'loaded' }, architecture: { input_modalities: ['text'], output_modalities: ['text'] }, context_length: 65536, meta: { instanceId: 'inst-a', gpus: [0], label: 'Qwen 3.6', aliases: ['qwen-q2_0'], n_ctx: 65536 } }]);
|
||||
});
|
||||
|
||||
test('the engine-reported window wins over the config', () => {
|
||||
@@ -37,8 +37,10 @@ test('only ready instances are listed, in input order', () => {
|
||||
ready({ id: 'd', apiModelId: 'm-d', status: 'unloading' }),
|
||||
ready({ id: 'e', apiModelId: 'm-e', context: 131072 }),
|
||||
]);
|
||||
assert.deepEqual(result.map(e => e.id), ['m-a', 'm-e']);
|
||||
assert.equal(result[1].meta.n_ctx, 131072);
|
||||
// #6180: the shared alias 'qwen-q2_0' differs from both canonical ids, so each ready instance also gets an alias row naming its owner.
|
||||
assert.deepEqual(result.map(e => e.id), ['m-a', 'qwen-q2_0', 'm-e', 'qwen-q2_0']);
|
||||
assert.deepEqual(result.map(e => e.alias_of), [undefined, 'm-a', undefined, 'm-e']);
|
||||
assert.equal(result[2].meta.n_ctx, 131072);
|
||||
});
|
||||
|
||||
test('empty input', () => {
|
||||
@@ -56,6 +58,6 @@ test('the input is not changed', () => {
|
||||
|
||||
test('n_ctx is the only key added to meta', () => {
|
||||
const [entry] = nativeModelEntries([ready()]);
|
||||
assert.deepEqual(Object.keys(entry).sort(), ['context_length', 'id', 'meta', 'object', 'owned_by'], 'context_length (#5893) beside the old keys');
|
||||
assert.deepEqual(Object.keys(entry).sort(), ['architecture', 'context_length', 'id', 'meta', 'object', 'owned_by', 'status'], 'status and architecture (#6180) beside the old keys');
|
||||
assert.deepEqual(Object.keys(entry.meta).sort(), ['aliases', 'gpus', 'instanceId', 'label', 'n_ctx']);
|
||||
});
|
||||
Reference in new issue
Block a user