okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7b06ea51b
main
1import type { NativeState } from './native' ; 2import type { ModelProviders , RemoteModelSelection } from './types' ; 3 4/** 5* Can the model that answers this chat take a picture, and if not, what does the person do next? 6* 7* One answer for the composer (the "+" button, paste and drop) and for Send, so they always agree. Pictures are on by default for every 8* model that can read them (owner rule); this says "no" only when the model cannot, or when it was loaded or set with pictures off. 9* - a local model: it was loaded with picture reading (`vision`); the catalog says whether this model could (and the engine has the reader); 10* - an API model: `reads` from the host (the person's switch, else what its server said, else on). 11*/ 12export type PictureStatus = 13| { ok :true } 14| { ok :false ; why :'none' | 'local-off' | 'local-cannot' | 'api-off' | 'api-style' ; message :string ; openModels :boolean }; 15 16export function pictureStatus ( native :NativeState | null , remote :RemoteModelSelection | null , providers :ModelProviders | null ) :PictureStatus { 17if ( remote ) { 18const connection = providers ?. connections . find ( c => c . id === remote . connectionId ); 19const model = connection ?. models . find ( m => m . id === remote . modelId ); 20if ( connection && connection . protocol !== 'openai-chat' ) return { ok :false , why :'api-style' , openModels :false , message :'Pictures can only be sent to model APIs that use the OpenAI chat style. Choose another model, or remove the picture.' }; 21if ( model ?. reads === false ) return { ok :false , why :'api-off' , openModels :true , message :'Picture reading is turned off for this model. Open Settings, Models, edit the connection and turn on Read pictures with this model, or choose another model.' }; 22return { ok :true }; 23} 24const instance = native ?. instances . find ( i => i . id === native . defaultId && i . status === 'ready' ); 25if ( ! instance ) return { ok :false , why :'none' , openModels :true , message :'Load a model that reads pictures first, then add the picture.' }; 26if ( instance . vision ) return { ok :true }; 27const size = native ?. catalog ?. families . flatMap ( f => f . sizes . map ( s => ({ ...s , images :f . images }))). find ( s => s . id === instance . model ); 28if ( size ?. images ) return { ok :false , why :'local-off' , openModels :true , message :'This model was started without picture reading. Open Models, turn on Read pictures and load it again.' }; 29return { ok :false , why :'local-cannot' , openModels :false , message :'This model cannot read pictures. Choose a model that reads pictures, or remove the picture.' }; 30}