okami.mom/strata

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

Niko1221Merge f-020-int into f-020-rel3d9c21509

main
3.6 KiB52 linesraw
1/** One answer for "can this model take a picture?" (src/lib/pictures.ts): the composer and Send agree, pictures are on by default. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFile } from 'node:fs/promises';
5import { transform } from 'esbuild';
6
7const source = await readFile(new URL('../src/lib/pictures.ts', import.meta.url), 'utf8');
8const { code } = await transform(source, { loader: 'ts', format: 'esm' });
9const { pictureStatus } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
10
11const native = (vision, { images = true, ready = true } = {}) => ({
12  defaultId: 'i1', instances: [{ id: 'i1', model: 'Gyro-S', status: ready ? 'ready' : 'loading', vision }],
13  catalog: { families: [{ family: 'gyro', images, sizes: [{ id: 'Gyro-S' }] }] },
14});
15const api = (model, protocol = 'openai-chat') => ({ connections: [{ id: 'c', protocol, models: [{ id: 'm', ...model }] }] });
16const pick = { connectionId: 'c', modelId: 'm' };
17
18test('a local model that was loaded with picture reading takes pictures', () => {
19  assert.equal(pictureStatus(native(true), null, null).ok, true);
20});
21
22test('a local model that could read pictures but was loaded without says what to do (the stale-flag case of imageissue2)', () => {
23  const r = pictureStatus(native(false), null, null);
24  assert.equal(r.ok, false); assert.equal(r.why, 'local-off'); assert.match(r.message, /Open Models, turn on Read pictures and load it again/);
25});
26
27test('a local model that cannot read pictures, and no model at all, say so plainly', () => {
28  assert.equal(pictureStatus(native(false, { images: false }), null, null).why, 'local-cannot');
29  assert.equal(pictureStatus(native(false, { ready: false }), null, null).why, 'none');
30  assert.equal(pictureStatus(null, null, null).why, 'none');
31});
32
33test('an API model takes pictures unless it was switched off or its server said no', () => {
34  assert.equal(pictureStatus(null, pick, api({})).ok, true, 'nothing said: on');
35  assert.equal(pictureStatus(null, pick, api({ reads: true })).ok, true);
36  const off = pictureStatus(null, pick, api({ reads: false }));
37  assert.equal(off.ok, false); assert.equal(off.why, 'api-off'); assert.match(off.message, /turn on Read pictures with this model/);
38  assert.equal(pictureStatus(null, pick, api({}, 'anthropic')).why, 'api-style');
39});
40
41const noModelSource = await readFile(new URL('../src/lib/no-model.ts', import.meta.url), 'utf8');
42const { noModelNotice } = await import(`data:text/javascript;base64,${Buffer.from((await transform(noModelSource, { loader: 'ts', format: 'esm' })).code).toString('base64')}`);
43test('no model: Send says so plainly, shows a running download, and stays quiet when a model can answer', () => {
44  assert.equal(noModelNotice({ instances: [], jobs: [] }).message, 'No model is loaded. Load one in Models first.');
45  assert.equal(noModelNotice(null).message, 'No model is loaded. Load one in Models first.');
46  assert.match(noModelNotice({ instances: [], jobs: [{ kind: 'install', state: 'running', result: { install: { download: { percent: 41.6 } } } }] }).message, /downloading \(42%\)/);
47  assert.match(noModelNotice({ instances: [{ status: 'loading' }], jobs: [] }).message, /still loading/);
48  assert.equal(noModelNotice({ instances: [{ status: 'ready' }], jobs: [] }), null);
49  assert.equal(noModelNotice({ instances: [], jobs: [] }, { remote: true }), null);
50  assert.equal(noModelNotice({ instances: [], jobs: [] }, { libraryLoaded: true }), null);
51  assert.equal(noModelNotice({ instances: [], jobs: [{ kind: 'benchmark', state: 'running' }] }).title, 'No model is loaded');
52});