plugins/mock/x64-cpu/src/catalogue.rs 6.5 KiB 231 lines Raw
1 //! The catalogue that the mock declares, and the numbers that go with it.2 //!3 //! The catalogue is the only description of a plugin that the core reads4 //! (spec section 16.3), so the mock writes it in full: one model, twelve5 //! capabilities, and a limit for every number that a capability can tune.6 7 use std::collections::BTreeMap;8 9 use inf3r_proto::body::{Cancel, Capability, Catalogue, Model, PartKind, Queue, Stops, Target};10 11 /// The name that the mock serves.12 pub const MODEL: &str = "mock";13 14 /// Sample rate of every audio channel that the mock makes.15 pub const RATE: u32 = 24_000;16 17 /// Length of every vector that the mock embeds.18 pub const DIMS: u32 = 8;19 20 /// The target: no device, no driver. The mock runs anywhere.21 pub const TARGET: &str = "x64-cpu";22 23 /// The smallest PNG: one pixel, black, fully opaque.24 ///25 /// A real encoder would be a dependency, and the mock only has to prove that an26 /// artifact crosses the wire with its bytes intact.27 pub const PNG: &[u8] = &[28     0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,29     0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4,30     0x89, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x00, 0x01, 0x00, 0x00,31     0x05, 0x00, 0x01, 0x0d, 0x0a, 0x2d, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae,32     0x42, 0x60, 0x82,33 ];34 35 /// The mp4 header that the mock emits as its clip.36 ///37 /// It is an `ftyp` box and nothing else. A player shows nothing, which is the38 /// honest answer for a plugin without a model, and a golden can still compare39 /// the bytes and the channel.40 pub const MP4: &[u8] = &[41     0x00, 0x00, 0x00, 0x18, b'f', b't', b'y', b'p', b'm', b'p', b'4', b'2', 0x00, 0x00, 0x00, 0x00,42     b'm', b'p', b'4', b'2', b'i', b's', b'o', b'm',43 ];44 45 /// The mock's catalogue and its constants.46 pub struct Mock {47     catalogue: Catalogue,48 }49 50 impl Default for Mock {51     fn default() -> Mock {52         Mock::new()53     }54 }55 56 impl Mock {57     /// The catalogue of the mock.58     pub fn new() -> Mock {59         Mock {60             catalogue: Catalogue {61                 target: Target {62                     id: TARGET.to_string(),63                     backend: "cpu".to_string(),64                     arch: vec![std::env::consts::ARCH.to_string()],65                     devices: 0,66                     vram_mb: Vec::new(),67                 },68                 models: vec![Model {69                     serve: MODEL.to_string(),70                     alias_of: None,71                     // The mock has no weights and loads nothing, so both72                     // numbers are zero and the reference still declares every73                     // fact.74                     weights_bytes: 0,75                     load_ms: 0,76                     capabilities: capabilities(),77                 }],78                 runtime: None,79                 cache: None,80             },81         }82     }83 84     /// The catalogue that `--describe` prints and `serve` sends.85     pub fn catalogue(&self) -> Catalogue {86         self.catalogue.clone()87     }88 }89 90 /// One capability per row of spec section 7.91 fn capabilities() -> BTreeMap<String, Capability> {92     let mut all = BTreeMap::new();93 94     all.insert(95         "chat".to_string(),96         capability(97             "chat.v1",98             &[99                 PartKind::Text,100                 PartKind::Image,101                 PartKind::Audio,102                 PartKind::Json,103             ],104             &["text", "progress"],105             &[("max_tokens", 256), ("temperature", 0), ("top_p", 0)],106         ),107     );108     all.insert(109         "embed".to_string(),110         capability(111             "embed.v1",112             &[PartKind::Text],113             &["embedding"],114             &[("dimensions", DIMS as u64)],115         ),116     );117     all.insert(118         "rerank".to_string(),119         capability(120             "rerank.v1",121             &[PartKind::Text, PartKind::Json],122             &["embedding"],123             &[],124         ),125     );126     all.insert(127         "decide".to_string(),128         capability(129             "decide.v1",130             &[PartKind::Text, PartKind::Json],131             &["decision"],132             &[],133         ),134     );135     all.insert(136         "extract".to_string(),137         capability(138             "extract.v1",139             &[PartKind::Text, PartKind::Json],140             &["decision"],141             &[],142         ),143     );144     all.insert(145         "tts".to_string(),146         capability(147             "tts.v1",148             &[PartKind::Text],149             &["pcm", "progress"],150             &[("rate", RATE as u64)],151         ),152     );153     all.insert(154         "stt".to_string(),155         capability(156             "stt.v1",157             &[PartKind::Audio, PartKind::Text],158             &["text", "tokens", "progress"],159             &[],160         ),161     );162     all.insert(163         "music".to_string(),164         capability(165             "music.v1",166             &[PartKind::Text, PartKind::Audio],167             &["pcm", "progress"],168             &[("rate", RATE as u64), ("duration_s", 1)],169         ),170     );171     all.insert(172         "image-gen".to_string(),173         capability(174             "image-gen.v1",175             &[PartKind::Text, PartKind::Image],176             &["image", "progress"],177             &[("steps", 4)],178         ),179     );180     all.insert(181         "image-edit".to_string(),182         capability(183             "image-edit.v1",184             &[PartKind::Image, PartKind::Text],185             &["image", "progress"],186             &[("steps", 4)],187         ),188     );189     all.insert(190         "t2v-gen".to_string(),191         capability(192             "t2v-gen.v1",193             &[PartKind::Text, PartKind::Image],194             &["clip", "progress"],195             &[("fps", 8), ("frames", 8)],196         ),197     );198     all.insert(199         "i2v-gen".to_string(),200         capability(201             "i2v-gen.v1",202             &[PartKind::Image, PartKind::Text],203             &["clip", "progress"],204             &[("fps", 8), ("frames", 8)],205         ),206     );207 208     all209 }210 211 fn capability(212     vocab: &str,213     parts: &[PartKind],214     channels: &[&str],215     limits: &[(&str, u64)],216 ) -> Capability {217     Capability {218         vocab: vocab.to_string(),219         parts: parts.to_vec(),220         channels: channels.iter().map(|name| (*name).to_string()).collect(),221         limits: limits222             .iter()223             .map(|(name, value)| ((*name).to_string(), *value))224             .collect(),225         // The mock is a well-behaved single-model server, so it names the226         // default of every lifecycle fact.227         cancel: Cancel::Token,228         stops: Stops::Plugin,229         queue: Queue::None,230     }231 }