okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-split-fb3 into f-split-int (locale keys re-added after the card-list strings)7b06ea51b

main
3.9 KiB66 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { mkdtempSync, rmSync } from 'node:fs';
4import { tmpdir } from 'node:os';
5import { join } from 'node:path';
6import { createVisionProbe, effectiveVision, modelReadsPictures } from '../server/vision-probe.mjs';
7import { createModelProviders } from '../server/model-providers.mjs';
8
9const answer = (routes, seen = []) => async (url, init) => {
10  const path = new URL(url).pathname;
11  seen.push(path);
12  const body = routes[path];
13  return body === undefined ? { ok: false, status: 404, json: async () => ({}) } : { ok: true, status: 200, json: async () => body };
14};
15
16test('a model list row says whether the model reads pictures in every common shape', () => {
17  assert.equal(modelReadsPictures({ architecture: { input_modalities: ['text', 'image'] } }), true);
18  assert.equal(modelReadsPictures({ architecture: { input_modalities: ['text'] } }), false);
19  assert.equal(modelReadsPictures({ modalities: { input: ['text', 'image'] } }), true);
20  assert.equal(modelReadsPictures({ capabilities: ['completion', 'vision'] }), true);
21  assert.equal(modelReadsPictures({ capabilities: { vision: false } }), false);
22  assert.equal(modelReadsPictures({ id: 'x' }), null);
23  assert.equal(modelReadsPictures(null), null);
24});
25
26test('what the person ticked wins over what the server said', () => {
27  assert.equal(effectiveVision({ vision: true }, false), true);
28  assert.equal(effectiveVision({ vision: false }, true), false);
29  assert.equal(effectiveVision({ vision: null }, true), true);
30  assert.equal(effectiveVision({}, undefined), undefined);
31});
32
33test('a llama-server started with --mmproj says so in /props, next to /v1, and the answer is cached', async () => {
34  const seen = [];
35  const probe = createVisionProbe({ fetcher: answer({ '/v1/models': { data: [{ id: 'smol' }] }, '/props': { modalities: { vision: true } } }, seen) });
36  const conn = { id: 'c1', baseUrl: 'http://127.0.0.1:8080/v1' };
37  assert.equal(probe.known(conn, 'smol'), undefined);
38  assert.equal(await probe.check(conn, 'smol'), true);
39  assert.equal(await probe.check(conn, 'smol'), true);
40  assert.equal(probe.known(conn, 'smol'), true);
41  assert.deepEqual(seen, ['/v1/models', '/props']);
42});
43
44test('a text-only server counts as not reading pictures; an unreachable one is unknown (pictures stay on by default)', async () => {
45  const text = createVisionProbe({ fetcher: answer({ '/v1/models': { data: [{ id: 'm' }] }, '/props': { modalities: { vision: false } } }) });
46  assert.equal(await text.check({ id: 'c', baseUrl: 'http://h/v1' }, 'm'), false);
47  const down = createVisionProbe({ fetcher: async () => { throw new Error('refused'); } });
48  assert.equal(await down.check({ id: 'c', baseUrl: 'http://h/v1' }, 'm'), null);
49});
50
51test('a provider list that names image input is believed without asking /props', async () => {
52  const seen = [];
53  const probe = createVisionProbe({ fetcher: answer({ '/v1/models': { data: [{ id: 'gpt', architecture: { input_modalities: ['text', 'image'] } }] } }, seen) });
54  assert.equal(await probe.check({ id: 'c', baseUrl: 'https://api.example.com/v1' }, 'gpt'), true);
55  assert.deepEqual(seen, ['/v1/models']);
56});
57
58test('the tick "This model reads pictures" is saved with the model and survives a reload', t => {
59  const directory = mkdtempSync(join(tmpdir(), 'strata-vision-'));
60  t.after(() => rmSync(directory, { recursive: true, force: true }));
61  const service = createModelProviders({ directory });
62  const saved = service.save({ kind: 'custom', name: 'Other PC', baseUrl: 'http://192.168.1.20:8080/v1', protocol: 'openai-chat', apiKey: '', models: [{ id: 'smol', name: 'SmolVLM', vision: true }, { id: 'text', name: 'Text only' }] }).connections[0];
63  assert.deepEqual(saved.models.map(m => m.vision), [true, null]);
64  const again = createModelProviders({ directory }).list().connections[0];
65  assert.deepEqual(again.models.map(m => m.vision), [true, null]);
66});