okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3d9c21509
main
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 } = {}) => ({ 12defaultId :'i1' , instances :[{ id :'i1' , model :'Gyro-S' , status :ready ?'ready' :'loading' , vision}], 13catalog :{ 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' , () => { 19assert . 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)' , () => { 23const r = pictureStatus ( native ( false ), null , null ); 24assert . 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' , () => { 28assert . equal ( pictureStatus ( native ( false , { images :false }), null , null ). why , 'local-cannot' ); 29assert . equal ( pictureStatus ( native ( false , { ready :false }), null , null ). why , 'none' ); 30assert . 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' , () => { 34assert . equal ( pictureStatus ( null , pick , api ({})). ok , true , 'nothing said: on' ); 35assert . equal ( pictureStatus ( null , pick , api ({ reads :true })). ok , true ); 36const off = pictureStatus ( null , pick , api ({ reads :false })); 37assert . equal ( off . ok , false ); assert . equal ( off . why , 'api-off' ); assert . match ( off . message , / turn on Read pictures with this model / ); 38assert . 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' , () => { 44assert . equal ( noModelNotice ({ instances :[], jobs :[] }). message , 'No model is loaded. Load one in Models first.' ); 45assert . equal ( noModelNotice ( null ). message , 'No model is loaded. Load one in Models first.' ); 46assert . match ( noModelNotice ({ instances :[], jobs :[{ kind :'install' , state :'running' , result :{ install :{ download :{ percent :41.6 } } } }] }). message , / downloading \(42%\) / ); 47assert . match ( noModelNotice ({ instances :[{ status :'loading' }], jobs :[] }). message , / still loading / ); 48assert . equal ( noModelNotice ({ instances :[{ status :'ready' }], jobs :[] }), null ); 49assert . equal ( noModelNotice ({ instances :[], jobs :[] }, { remote :true }), null ); 50assert . equal ( noModelNotice ({ instances :[], jobs :[] }, { libraryLoaded :true }), null ); 51assert . equal ( noModelNotice ({ instances :[], jobs :[{ kind :'benchmark' , state :'running' }] }). title , 'No model is loaded' ); 52});