Skip to main content

kjarni_cli/
lib.rs

1use clap::{Parser, Subcommand};
2
3/// Default model for `kjarni chat`.
4///
5/// Must be a CLI name that `ModelType::from_cli_name` resolves, or the bare
6/// `kjarni chat` command fails for everyone. `tests::default_models_exist` checks
7/// this and [`DEFAULT_GENERATE_MODEL`] against the registry.
8pub const DEFAULT_CHAT_MODEL: &str = "llama3.2-3b-instruct";
9
10/// Default model for `kjarni generate`.
11pub const DEFAULT_GENERATE_MODEL: &str = "llama3.2-1b-instruct";
12
13#[derive(Parser)]
14#[command(name = "kjarni")]
15#[command(
16    about = "Run transformer models on your own machine. Same output as PyTorch, no Python, no server.",
17    long_about = None
18)]
19#[command(version)]
20pub struct Cli {
21    #[command(subcommand)]
22    pub command: Commands,
23
24    /// Verbosity level (-v, -vv, -vvv)
25    #[arg(short, long, action = clap::ArgAction::Count, global = true)]
26    pub verbose: u8,
27}
28
29#[derive(Subcommand, Debug, PartialEq)]
30pub enum Commands {
31    /// Manage models (list, download, info)
32    Model {
33        #[command(subcommand)]
34        action: ModelCommands,
35    },
36
37    /// Generate text from a prompt
38    Generate {
39        /// The prompt (or file path, or stdin if not provided)
40        prompt: Option<String>,
41
42        #[arg(short, long, default_value = DEFAULT_GENERATE_MODEL)]
43        model: String,
44
45        /// Load weights from a local file or directory instead of the registry
46        #[arg(long)]
47        model_path: Option<String>,
48
49        /// Maximum tokens to generate
50        #[arg(short = 'n', long, default_value_t = 100)]
51        max_tokens: usize,
52
53        /// Sampling temperature (0.0 = greedy, higher = more random)
54        #[arg(short, long, default_value_t = 0.7)]
55        temperature: f32,
56
57        /// Top-K sampling (limits to K most likely tokens)
58        #[arg(long)]
59        top_k: Option<usize>,
60
61        /// Top-P (nucleus) sampling threshold
62        #[arg(long)]
63        top_p: Option<f32>,
64
65        /// Min-P sampling threshold  
66        #[arg(long)]
67        min_p: Option<f32>,
68
69        /// Repetition penalty (1.0 = no penalty)
70        #[arg(long, default_value_t = 1.1)]
71        repetition_penalty: f32,
72
73        /// Use greedy decoding (ignores temperature)
74        #[arg(long)]
75        greedy: bool,
76
77        /// Use GPU
78        #[arg(long)]
79        gpu: bool,
80
81        /// Disable streaming output
82        #[arg(long)]
83        no_stream: bool,
84
85        /// Suppress status messages
86        #[arg(short, long)]
87        quiet: bool,
88
89        /// Prefer quantized GGUF weights when the model has them
90        ///
91        /// Q4_K_M is a fraction of the size and markedly faster to decode:
92        /// measured on an RTX A2000, llama3.2-3b runs 24.5 tok/s from GGUF
93        /// against 8.7 from full-precision safetensors. Falls back with a notice
94        /// when the model has no GGUF published.
95        #[arg(long)]
96        gguf: bool,
97
98        /// Draft model for speculative decoding. Must share the target's
99        /// vocabulary: a small model of the same family, such as
100        /// qwen2.5-0.5b-instruct drafting for qwen2.5-1.5b.
101        #[arg(long)]
102        draft: Option<String>,
103
104        /// Tokens the draft proposes per round. Higher trades wasted draft work
105        /// against fewer passes over the target's weights.
106        #[arg(long, default_value_t = 4)]
107        draft_tokens: usize,
108
109        /// Speculate from earlier in the text instead of with a draft model, matching
110        /// up to this many tokens. Helps where the output repeats the input.
111        #[arg(long, value_name = "NGRAM")]
112        prompt_lookup: Option<usize>,
113    },
114
115    /// Summarize text
116    Summarize {
117        /// Input text (or read from stdin)
118        #[arg(short, long)]
119        input: Option<String>,
120
121        /// Model to use
122        #[arg(short, long, default_value = "distilbart-cnn")]
123        model: String,
124
125        /// Path to local model
126        /// Load weights from a local file or directory instead of the registry
127        #[arg(long)]
128        model_path: Option<String>,
129
130        /// Minimum summary length
131        #[arg(long)]
132        min_length: Option<usize>,
133
134        /// Maximum summary length
135        #[arg(long)]
136        max_length: Option<usize>,
137
138        /// Number of beams for beam search
139        #[arg(long)]
140        num_beams: Option<usize>,
141
142        /// Length penalty for beam search (< 1 shorter, > 1 longer)
143        #[arg(long)]
144        length_penalty: Option<f32>,
145
146        /// Block repeated n-grams of this size
147        #[arg(long)]
148        no_repeat_ngram: Option<usize>,
149
150        /// Use greedy decoding (deterministic, fastest)
151        #[arg(long)]
152        greedy: bool,
153
154        /// Disable streaming output
155        #[arg(long)]
156        no_stream: bool,
157
158        /// Use GPU
159        #[arg(long)]
160        gpu: bool,
161
162        /// Suppress progress messages
163        #[arg(short, long)]
164        quiet: bool,
165    },
166
167    /// Translate text between languages
168    Translate {
169        /// Input text (or read from stdin)
170        #[arg(short, long)]
171        input: Option<String>,
172
173        /// Model to use. By default opus-mt-en-de or opus-mt-de-en for those two
174        /// directions, and flan-t5-base, which is much less reliable, for the rest
175        #[arg(short, long)]
176        model: Option<String>,
177
178        /// Path to local model
179        /// Load weights from a local file or directory instead of the registry
180        #[arg(long)]
181        model_path: Option<String>,
182
183        /// Source language (e.g., en, de, fr)
184        #[arg(long)]
185        src: Option<String>,
186
187        /// Target language (e.g., en, de, fr)
188        #[arg(long)]
189        dst: Option<String>,
190
191        /// Maximum output length
192        #[arg(long)]
193        max_length: Option<usize>,
194
195        /// Number of beams for beam search
196        #[arg(long)]
197        num_beams: Option<usize>,
198
199        /// Length penalty for beam search (< 1 shorter, > 1 longer)
200        #[arg(long)]
201        length_penalty: Option<f32>,
202
203        /// Block repeated n-grams of this size
204        #[arg(long)]
205        no_repeat_ngram: Option<usize>,
206
207        /// Use greedy decoding (deterministic, fastest)
208        #[arg(long)]
209        greedy: bool,
210
211        /// Disable streaming output
212        #[arg(long)]
213        no_stream: bool,
214
215        /// Use GPU
216        #[arg(long)]
217        gpu: bool,
218
219        /// Suppress progress messages
220        #[arg(short, long)]
221        quiet: bool,
222    },
223
224    /// Show a model's metadata, config and tensor layout
225    Inspect {
226        /// Path to a .gguf, a .safetensors directory, or a name in ~/.cache/kjarni
227        path: String,
228    },
229
230    /// Generate embeddings for text
231    Embed {
232        /// Input text, file path, or stdin if not provided
233        input: Option<String>,
234
235        /// Embedding model
236        #[arg(short, long, default_value = "minilm-l6-v2")]
237        model: String,
238
239        /// Load weights from a local file or directory instead of the registry
240        #[arg(long)]
241        model_path: Option<String>,
242
243        /// Output format: raw, json
244        #[arg(long, default_value = "raw")]
245        format: String,
246
247        /// Keep the raw pooled vector instead of scaling it to unit length
248        #[arg(long)]
249        no_normalize: bool,
250
251        /// Scale each vector to unit length, which is the default
252        #[arg(long, hide = true, conflicts_with = "no_normalize")]
253        normalize: bool,
254
255        /// Pooling strategy: mean, cls, max
256        ///
257        /// Mean matches what sentence-transformers does for these models, and what the
258        /// library bindings and presets already default to. Pooling changes the vector
259        /// itself, so a different choice here does not produce a slightly different
260        /// answer, it produces one that cannot be compared against the others.
261        #[arg(long, default_value = "mean")]
262        pooling: String,
263
264        /// Run on the GPU
265        #[arg(long)]
266        gpu: bool,
267
268        /// Suppress status messages
269        #[arg(short, long)]
270        quiet: bool,
271    },
272
273    /// Serve Kjarni's tools to AI agents over MCP (stdio): folder search,
274    /// transcription, classification, reranking and similarity
275    Mcp,
276
277    /// Transcribe audio to text
278    Transcribe {
279        /// Path to audio file (wav, mp3, flac, ogg)
280        file: String,
281
282        /// Model to use (whisper-small, whisper-large-v3)
283        #[arg(short, long, default_value = "whisper-small")]
284        model: String,
285
286        /// Path to local model directory (not yet implemented)
287        /// Load weights from a local file or directory instead of the registry
288        #[arg(long)]
289        model_path: Option<String>,
290
291        /// Language code (e.g., en, fr, de). Omit for auto-detect.
292        #[arg(short, long)]
293        language: Option<String>,
294
295        /// Translate to English instead of transcribing
296        #[arg(long)]
297        translate: bool,
298
299        /// Include timestamps in output
300        #[arg(short, long)]
301        timestamps: bool,
302
303        /// Maximum tokens per 30-second chunk
304        #[arg(long)]
305        max_tokens: Option<usize>,
306
307        /// Disable streaming (wait for full result)
308        #[arg(long)]
309        no_stream: bool,
310
311        /// Use GPU acceleration
312        #[arg(long)]
313        gpu: bool,
314
315        /// Suppress progress output
316        #[arg(short, long)]
317        quiet: bool,
318    },
319
320    /// Classify text using a classification model
321    Classify {
322        /// Input text(s) to classify. Use - for stdin.
323        input: Vec<String>,
324
325        /// Model name from registry
326        #[arg(short, long, default_value = "distilbert-sentiment")]
327        model: String,
328
329        /// Load model from local path instead of registry
330        #[arg(long, value_name = "PATH")]
331        model_path: Option<String>,
332
333        /// Custom labels (comma-separated, order must match model output)
334        /// Example: --labels "negative,positive" or --labels "neikvætt,jákvætt"
335        #[arg(long, value_name = "LABELS")]
336        labels: Option<String>,
337
338        /// Return top K predictions
339        #[arg(long, default_value = "5")]
340        top_k: usize,
341
342        /// Minimum confidence threshold (0.0-1.0)
343        #[arg(long)]
344        threshold: Option<f32>,
345
346        /// Maximum sequence length (truncates longer inputs)
347        #[arg(long)]
348        max_length: Option<usize>,
349
350        /// Batch size for inference
351        #[arg(long)]
352        batch_size: Option<usize>,
353
354        /// Use multi-label classification (sigmoid instead of softmax)
355        #[arg(long)]
356        multi_label: bool,
357
358        /// Output format: json, jsonl, text
359        #[arg(short, long, default_value = "text")]
360        format: String,
361
362        /// Run on GPU
363        #[arg(long)]
364        gpu: bool,
365
366        /// Model precision: f32, f16, bf16
367        #[arg(long)]
368        dtype: Option<String>,
369
370        /// Suppress progress output
371        #[arg(short, long)]
372        quiet: bool,
373    },
374
375    /// Rerank documents by relevance to a query
376    Rerank {
377        /// The query to rank against
378        query: String,
379
380        /// Documents to rerank (or read from stdin, one per line)
381        documents: Vec<String>,
382
383        #[arg(short, long, default_value = "minilm-l6-v2-cross-encoder")]
384        model: String,
385
386        /// Load weights from a local file or directory instead of the registry
387        #[arg(long)]
388        model_path: Option<String>,
389
390        /// Return only top K results
391        #[arg(short = 'k', long)]
392        top_k: Option<usize>,
393
394        /// Output format: json, jsonl, text, docs
395        #[arg(short, long, default_value = "text")]
396        format: String,
397
398        /// Run on the GPU
399        #[arg(long)]
400        gpu: bool,
401
402        /// Suppress progress output
403        #[arg(short, long)]
404        quiet: bool,
405    },
406
407    /// Interactive chat mode
408    Chat {
409        #[arg(short, long, default_value = DEFAULT_CHAT_MODEL)]
410        model: String,
411
412        /// Load weights from a local file or directory instead of the registry
413        #[arg(long)]
414        model_path: Option<String>,
415
416        /// System prompt to set assistant behavior
417        #[arg(short, long)]
418        system: Option<String>,
419
420        /// Sampling temperature
421        #[arg(short, long, default_value_t = 0.7)]
422        temperature: f32,
423
424        /// Max tokens per response
425        #[arg(short = 'n', long, default_value_t = 512)]
426        max_tokens: usize,
427
428        /// Run on the GPU
429        #[arg(long)]
430        gpu: bool,
431
432        /// Suppress progress output
433        #[arg(short, long)]
434        quiet: bool,
435
436        /// Prefer quantized GGUF weights when the model has them
437        ///
438        /// Q4_K_M is a fraction of the size and markedly faster to decode:
439        /// measured on an RTX A2000, llama3.2-3b runs 24.5 tok/s from GGUF
440        /// against 8.7 from full-precision safetensors. Falls back with a notice
441        /// when the model has no GGUF published.
442        #[arg(long)]
443        gguf: bool,
444
445        /// Draft model for speculative decoding. Must share the target's
446        /// vocabulary, such as qwen2.5-0.5b-instruct drafting for qwen2.5-1.5b.
447        #[arg(long)]
448        draft: Option<String>,
449
450        /// Tokens the draft proposes per round.
451        #[arg(long, default_value_t = 4)]
452        draft_tokens: usize,
453    },
454
455    /// Create or manage search indexes
456    Index {
457        #[command(subcommand)]
458        action: IndexCommands,
459    },
460
461    /// Index and search images by description
462    #[cfg(feature = "image-io")]
463    Image {
464        #[command(subcommand)]
465        action: ImageCommands,
466    },
467
468    /// Search an index
469    Search {
470        /// Path to the index file
471        index_path: String,
472
473        /// Search query
474        query: String,
475
476        /// Number of results to return
477        #[arg(short = 'k', long, default_value_t = 10)]
478        top_k: usize,
479
480        /// Search mode: hybrid, semantic, keyword
481        #[arg(long, default_value = "hybrid")]
482        mode: String,
483
484        /// Encoder model for semantic search. Defaults to the model the index was
485        /// built with.
486        #[arg(short, long)]
487        model: Option<String>,
488
489        /// Reranking model (optional)
490        /// Use a cross-encoder model to rerank initial results
491        /// Example: --rerank-model "ms-marco-minilm"
492        #[arg(long, default_value = None)]
493        rerank_model: Option<String>,
494
495        /// Output format: json, jsonl, text
496        #[arg(short, long, default_value = "text")]
497        format: String,
498
499        /// Run on the GPU
500        #[arg(long)]
501        gpu: bool,
502
503        /// Suppress progress output
504        #[arg(short, long)]
505        quiet: bool,
506    },
507
508    /// Compute similarity between two texts
509    Similarity {
510        /// First text (or file path)
511        text1: String,
512
513        /// Second text (or file path)
514        text2: String,
515
516        /// Encoder model
517        #[arg(short, long, default_value = "minilm-l6-v2")]
518        model: String,
519
520        /// Run on the GPU
521        #[arg(long)]
522        gpu: bool,
523
524        /// Suppress progress output
525        #[arg(short, long)]
526        quiet: bool,
527    },
528}
529
530#[derive(Subcommand, Debug, PartialEq)]
531pub enum ModelCommands {
532    /// List all available models
533    List {
534        /// Filter by architecture (e.g., llama, bert, t5)
535        #[arg(short, long)]
536        arch: Option<String>,
537
538        /// Filter by task (e.g., chat, embedding, classification, summarization)
539        #[arg(short, long)]
540        task: Option<String>,
541
542        /// Show only downloaded models
543        #[arg(short, long)]
544        downloaded: bool,
545    },
546
547    /// Download a model
548    Download {
549        name: String,
550
551        #[arg(long)]
552        gguf: bool,
553
554        #[arg(short, long)]
555        quiet: bool,
556    },
557
558    /// Remove a downloaded model
559    Remove { name: String },
560
561    /// Show detailed info about a model
562    Info { name: String },
563
564    /// Search for models by name or description
565    Search { query: String },
566}
567
568#[derive(Subcommand, Debug, PartialEq)]
569pub enum InspectCommands {
570    /// Inspect a model file
571    Model {
572        /// Path to the model file
573        path: String,
574    },
575}
576
577/// Image search, backed by CLIP.
578///
579/// Separate from `index`/`search` because the vectors are not interchangeable:
580/// a CLIP image vector and a MiniLM text vector live in different spaces, and
581/// comparing them would return confident nonsense.
582#[cfg(feature = "image-io")]
583#[derive(Subcommand, Debug, PartialEq)]
584pub enum ImageCommands {
585    /// Embed images into a searchable index
586    Index {
587        /// Files or directories of images
588        #[arg(required = true)]
589        inputs: Vec<String>,
590
591        /// Where to write the index
592        #[arg(short, long, default_value = "images.json")]
593        output: String,
594
595        /// Suppress progress output
596        #[arg(short, long)]
597        quiet: bool,
598    },
599
600    /// Find images matching a description
601    Search {
602        /// Path to the image index
603        index_path: String,
604
605        /// What to look for, in words
606        query: String,
607
608        /// Number of results
609        #[arg(short = 'k', long, default_value_t = 5)]
610        top_k: usize,
611
612        /// Suppress progress output
613        #[arg(short, long)]
614        quiet: bool,
615    },
616}
617
618#[derive(Subcommand, Debug, PartialEq)]
619pub enum IndexCommands {
620    /// Create a new index from documents
621    Create {
622        /// Output index file path
623        output: String,
624
625        /// Input files/directories (uses built-in chunking)
626        #[arg(conflicts_with = "from_chunks")]
627        inputs: Vec<String>,
628
629        /// Pre-chunked JSONL file (bypass chunking)
630        #[arg(long, conflicts_with = "inputs")]
631        from_chunks: Option<String>,
632
633        /// Chunk size in characters
634        ///
635        /// The default fits inside the encoder's window. minilm-l6-v2 reads 256
636        /// tokens, roughly 900 characters, so at 1000 about nine chunks in ten
637        /// would be longer than the model reads, with the tail dropped silently.
638        /// The C# Indexer uses 512 too.
639        #[arg(long, default_value_t = 512)]
640        chunk_size: usize,
641
642        /// Chunk overlap in characters
643        #[arg(long, default_value_t = 100)]
644        chunk_overlap: usize,
645
646        /// Encoder model for embeddings
647        #[arg(short, long, default_value = "minilm-l6-v2")]
648        model: String,
649
650        /// Run on the GPU
651        #[arg(long)]
652        gpu: bool,
653
654        /// Suppress progress output
655        #[arg(short, long)]
656        quiet: bool,
657    },
658
659    /// Add files to an existing index, replacing any it already holds
660    Add {
661        /// Index file path
662        index_path: String,
663
664        /// Input files or directories to add
665        inputs: Vec<String>,
666
667        /// Chunk size in characters
668        ///
669        /// Matches `index create`; see the note there.
670        #[arg(long, default_value_t = 512)]
671        chunk_size: usize,
672
673        #[arg(long, default_value_t = 100)]
674        chunk_overlap: usize,
675
676        /// Encoder model. Defaults to the model the index was built with.
677        #[arg(short, long)]
678        model: Option<String>,
679
680        /// Run on the GPU
681        #[arg(long)]
682        gpu: bool,
683
684        /// Suppress progress output
685        #[arg(short, long)]
686        quiet: bool,
687    },
688
689    /// Remove files or folders from an index
690    Remove {
691        /// Index file path
692        index_path: String,
693
694        /// Files or folders to remove, which need not still exist
695        #[arg(required = true)]
696        paths: Vec<String>,
697
698        /// Suppress progress output
699        #[arg(short, long)]
700        quiet: bool,
701    },
702
703    /// Show index info
704    Info {
705        /// Index file path
706        index_path: String,
707    },
708}
709
710/// Convert verbosity count to log level string
711pub fn verbosity_to_log_level(verbose: u8) -> &'static str {
712    match verbose {
713        0 => "warn",
714        1 => "info",
715        2 => "debug",
716        _ => "trace",
717    }
718}
719
720#[cfg(test)]
721mod tests {
722    use super::*;
723    use clap::Parser;
724
725    /// Every model name hardcoded outside the registry must actually resolve.
726    ///
727    /// This exists because three separate lists had drifted from the registry at
728    /// once: both CLI defaults, and four of the seven entries in
729    /// `kjarni::chat::suggest_chat_models`. Each was presumably correct when
730    /// written and went stale when models gained an `-instruct` suffix, with
731    /// nothing to notice. A name that does not resolve is a user-facing failure
732    /// on the very first command someone types, so it should break the build
733    /// instead.
734    #[test]
735    fn hardcoded_model_names_resolve() {
736        use kjarni::ModelType;
737
738        let mut bad = Vec::new();
739
740        for name in [DEFAULT_CHAT_MODEL, DEFAULT_GENERATE_MODEL] {
741            if ModelType::from_cli_name(name).is_none() {
742                bad.push(format!("CLI default '{name}'"));
743            }
744        }
745
746        for name in kjarni::chat::suggested_models() {
747            if ModelType::from_cli_name(name).is_none() {
748                bad.push(format!("chat suggestion '{name}'"));
749            }
750        }
751
752        assert!(
753            bad.is_empty(),
754            "these names are not in the model registry, so anyone who uses them \
755             gets an error:\n  {}\n\
756             Run `kjarni model list` for the valid names.",
757            bad.join("\n  ")
758        );
759    }
760
761    /// The chat default must be usable for chat, not merely a real model.
762    ///
763    /// `kjarni chat` with no arguments should work; defaulting to an embedding
764    /// model would resolve fine here and still fail at runtime.
765    #[test]
766    fn default_chat_model_is_a_chat_model() {
767        assert!(
768            kjarni::chat::is_chat_model(DEFAULT_CHAT_MODEL).is_ok(),
769            "DEFAULT_CHAT_MODEL '{DEFAULT_CHAT_MODEL}' cannot be used for chat"
770        );
771    }
772    fn parse_args(args: &[&str]) -> Result<Cli, clap::Error> {
773        let mut full_args = vec!["kjarni"];
774        full_args.extend(args);
775        Cli::try_parse_from(full_args)
776    }
777
778    #[test]
779    fn test_verbosity_to_log_level_zero() {
780        assert_eq!(verbosity_to_log_level(0), "warn");
781    }
782
783    #[test]
784    fn test_verbosity_to_log_level_one() {
785        assert_eq!(verbosity_to_log_level(1), "info");
786    }
787
788    #[test]
789    fn test_verbosity_to_log_level_two() {
790        assert_eq!(verbosity_to_log_level(2), "debug");
791    }
792
793    #[test]
794    fn test_verbosity_to_log_level_three() {
795        assert_eq!(verbosity_to_log_level(3), "trace");
796    }
797
798    #[test]
799    fn test_verbosity_to_log_level_high() {
800        assert_eq!(verbosity_to_log_level(10), "trace");
801        assert_eq!(verbosity_to_log_level(255), "trace");
802    }
803
804    #[test]
805    fn test_generate_minimal() {
806        let cli = parse_args(&["generate"]).unwrap();
807
808        match cli.command {
809            Commands::Generate {
810                prompt,
811                model,
812                max_tokens,
813                temperature,
814                greedy,
815                gpu,
816                quiet,
817                ..
818            } => {
819                assert!(prompt.is_none());
820                assert_eq!(model, DEFAULT_GENERATE_MODEL);
821                assert_eq!(max_tokens, 100);
822                assert!((temperature - 0.7).abs() < 0.001);
823                assert!(!greedy);
824                assert!(!gpu);
825                assert!(!quiet);
826            }
827            _ => panic!("Expected Generate command"),
828        }
829    }
830
831    #[test]
832    fn test_generate_with_prompt() {
833        let cli = parse_args(&["generate", "Hello world"]).unwrap();
834
835        match cli.command {
836            Commands::Generate { prompt, .. } => {
837                assert_eq!(prompt, Some("Hello world".to_string()));
838            }
839            _ => panic!("Expected Generate command"),
840        }
841    }
842
843    #[test]
844    fn test_generate_with_model() {
845        let cli = parse_args(&["generate", "-m", "phi3.5-mini"]).unwrap();
846
847        match cli.command {
848            Commands::Generate { model, .. } => {
849                assert_eq!(model, "phi3.5-mini");
850            }
851            _ => panic!("Expected Generate command"),
852        }
853    }
854
855    #[test]
856    fn test_generate_with_max_tokens() {
857        let cli = parse_args(&["generate", "-n", "500"]).unwrap();
858
859        match cli.command {
860            Commands::Generate { max_tokens, .. } => {
861                assert_eq!(max_tokens, 500);
862            }
863            _ => panic!("Expected Generate command"),
864        }
865    }
866
867    #[test]
868    fn test_generate_with_temperature() {
869        let cli = parse_args(&["generate", "-t", "1.5"]).unwrap();
870
871        match cli.command {
872            Commands::Generate { temperature, .. } => {
873                assert!((temperature - 1.5).abs() < 0.001);
874            }
875            _ => panic!("Expected Generate command"),
876        }
877    }
878
879    #[test]
880    fn test_generate_with_sampling_params() {
881        let cli = parse_args(&[
882            "generate", "--top-k", "50", "--top-p", "0.9", "--min-p", "0.05",
883        ])
884        .unwrap();
885
886        match cli.command {
887            Commands::Generate {
888                top_k,
889                top_p,
890                min_p,
891                ..
892            } => {
893                assert_eq!(top_k, Some(50));
894                assert_eq!(top_p, Some(0.9));
895                assert_eq!(min_p, Some(0.05));
896            }
897            _ => panic!("Expected Generate command"),
898        }
899    }
900
901    #[test]
902    fn test_generate_with_greedy() {
903        let cli = parse_args(&["generate", "--greedy"]).unwrap();
904
905        match cli.command {
906            Commands::Generate { greedy, .. } => {
907                assert!(greedy);
908            }
909            _ => panic!("Expected Generate command"),
910        }
911    }
912
913    #[test]
914    fn test_generate_with_gpu() {
915        let cli = parse_args(&["generate", "--gpu"]).unwrap();
916
917        match cli.command {
918            Commands::Generate { gpu, .. } => {
919                assert!(gpu);
920            }
921            _ => panic!("Expected Generate command"),
922        }
923    }
924
925    #[test]
926    fn test_generate_with_no_stream() {
927        let cli = parse_args(&["generate", "--no-stream"]).unwrap();
928
929        match cli.command {
930            Commands::Generate { no_stream, .. } => {
931                assert!(no_stream);
932            }
933            _ => panic!("Expected Generate command"),
934        }
935    }
936
937    #[test]
938    fn test_generate_with_quiet() {
939        let cli = parse_args(&["generate", "-q"]).unwrap();
940
941        match cli.command {
942            Commands::Generate { quiet, .. } => {
943                assert!(quiet);
944            }
945            _ => panic!("Expected Generate command"),
946        }
947    }
948
949    #[test]
950    fn test_generate_all_options() {
951        let cli = parse_args(&[
952            "generate",
953            "test prompt",
954            "-m",
955            "llama3.2-3b-instruct",
956            "-n",
957            "256",
958            "-t",
959            "0.8",
960            "--top-k",
961            "40",
962            "--top-p",
963            "0.95",
964            "--repetition-penalty",
965            "1.2",
966            "--greedy",
967            "--gpu",
968            "--no-stream",
969            "-q",
970        ])
971        .unwrap();
972
973        match cli.command {
974            Commands::Generate {
975                prompt,
976                model,
977                max_tokens,
978                temperature,
979                top_k,
980                top_p,
981                repetition_penalty,
982                greedy,
983                gpu,
984                no_stream,
985                quiet,
986                ..
987            } => {
988                assert_eq!(prompt, Some("test prompt".to_string()));
989                assert_eq!(model, "llama3.2-3b-instruct");
990                assert_eq!(max_tokens, 256);
991                assert!((temperature - 0.8).abs() < 0.001);
992                assert_eq!(top_k, Some(40));
993                assert_eq!(top_p, Some(0.95));
994                assert!((repetition_penalty - 1.2).abs() < 0.001);
995                assert!(greedy);
996                assert!(gpu);
997                assert!(no_stream);
998                assert!(quiet);
999            }
1000            _ => panic!("Expected Generate command"),
1001        }
1002    }
1003
1004    #[test]
1005    fn test_chat_defaults() {
1006        let cli = parse_args(&["chat"]).unwrap();
1007
1008        match cli.command {
1009            Commands::Chat {
1010                model,
1011                system,
1012                temperature,
1013                max_tokens,
1014                gpu,
1015                quiet,
1016                ..
1017            } => {
1018                assert_eq!(model, DEFAULT_CHAT_MODEL);
1019                assert!(system.is_none());
1020                assert!((temperature - 0.7).abs() < 0.001);
1021                assert_eq!(max_tokens, 512);
1022                assert!(!gpu);
1023                assert!(!quiet);
1024            }
1025            _ => panic!("Expected Chat command"),
1026        }
1027    }
1028
1029    #[test]
1030    fn test_chat_with_system_prompt() {
1031        let cli = parse_args(&["chat", "-s", "You are a helpful assistant"]).unwrap();
1032
1033        match cli.command {
1034            Commands::Chat { system, .. } => {
1035                assert_eq!(system, Some("You are a helpful assistant".to_string()));
1036            }
1037            _ => panic!("Expected Chat command"),
1038        }
1039    }
1040
1041    #[test]
1042    fn test_chat_with_model() {
1043        let cli = parse_args(&["chat", "-m", "phi3.5-mini"]).unwrap();
1044
1045        match cli.command {
1046            Commands::Chat { model, .. } => {
1047                assert_eq!(model, "phi3.5-mini");
1048            }
1049            _ => panic!("Expected Chat command"),
1050        }
1051    }
1052
1053    #[test]
1054    fn test_classify_defaults() {
1055        let cli = parse_args(&["classify"]).unwrap();
1056
1057        match cli.command {
1058            Commands::Classify {
1059                input,
1060                model,
1061                top_k,
1062                format,
1063                multi_label,
1064                gpu,
1065                quiet,
1066                ..
1067            } => {
1068                assert!(input.is_empty());
1069                assert_eq!(model, "distilbert-sentiment");
1070                assert_eq!(top_k, 5);
1071                assert_eq!(format, "text");
1072                assert!(!multi_label);
1073                assert!(!gpu);
1074                assert!(!quiet);
1075            }
1076            _ => panic!("Expected Classify command"),
1077        }
1078    }
1079
1080    #[test]
1081    fn test_classify_with_input() {
1082        let cli = parse_args(&["classify", "This is great!"]).unwrap();
1083
1084        match cli.command {
1085            Commands::Classify { input, .. } => {
1086                assert_eq!(input, vec!["This is great!".to_string()]);
1087            }
1088            _ => panic!("Expected Classify command"),
1089        }
1090    }
1091
1092    #[test]
1093    fn test_classify_with_multiple_inputs() {
1094        let cli = parse_args(&["classify", "text one", "text two", "text three"]).unwrap();
1095
1096        match cli.command {
1097            Commands::Classify { input, .. } => {
1098                assert_eq!(input.len(), 3);
1099                assert_eq!(input[0], "text one");
1100                assert_eq!(input[1], "text two");
1101                assert_eq!(input[2], "text three");
1102            }
1103            _ => panic!("Expected Classify command"),
1104        }
1105    }
1106
1107    #[test]
1108    fn test_classify_with_labels() {
1109        let cli = parse_args(&["classify", "--labels", "bad,good"]).unwrap();
1110
1111        match cli.command {
1112            Commands::Classify { labels, .. } => {
1113                assert_eq!(labels, Some("bad,good".to_string()));
1114            }
1115            _ => panic!("Expected Classify command"),
1116        }
1117    }
1118
1119    #[test]
1120    fn test_classify_with_multi_label() {
1121        let cli = parse_args(&["classify", "--multi-label"]).unwrap();
1122
1123        match cli.command {
1124            Commands::Classify { multi_label, .. } => {
1125                assert!(multi_label);
1126            }
1127            _ => panic!("Expected Classify command"),
1128        }
1129    }
1130
1131    #[test]
1132    fn test_search_minimal() {
1133        let cli = parse_args(&["search", "./index", "my query"]).unwrap();
1134
1135        match cli.command {
1136            Commands::Search {
1137                index_path,
1138                query,
1139                top_k,
1140                mode,
1141                model,
1142                format,
1143                ..
1144            } => {
1145                assert_eq!(index_path, "./index");
1146                assert_eq!(query, "my query");
1147                assert_eq!(top_k, 10);
1148                assert_eq!(mode, "hybrid");
1149                assert_eq!(model, None);
1150                assert_eq!(format, "text");
1151            }
1152            _ => panic!("Expected Search command"),
1153        }
1154    }
1155
1156    #[test]
1157    fn test_search_with_top_k() {
1158        let cli = parse_args(&["search", "./index", "query", "-k", "20"]).unwrap();
1159
1160        match cli.command {
1161            Commands::Search { top_k, .. } => {
1162                assert_eq!(top_k, 20);
1163            }
1164            _ => panic!("Expected Search command"),
1165        }
1166    }
1167
1168    #[test]
1169    fn test_search_with_mode() {
1170        let cli = parse_args(&["search", "./index", "query", "--mode", "semantic"]).unwrap();
1171
1172        match cli.command {
1173            Commands::Search { mode, .. } => {
1174                assert_eq!(mode, "semantic");
1175            }
1176            _ => panic!("Expected Search command"),
1177        }
1178    }
1179
1180    #[test]
1181    fn test_search_with_rerank_model() {
1182        let cli = parse_args(&[
1183            "search",
1184            "./index",
1185            "query",
1186            "--rerank-model",
1187            "ms-marco-minilm",
1188        ])
1189        .unwrap();
1190
1191        match cli.command {
1192            Commands::Search { rerank_model, .. } => {
1193                assert_eq!(rerank_model, Some("ms-marco-minilm".to_string()));
1194            }
1195            _ => panic!("Expected Search command"),
1196        }
1197    }
1198
1199    #[test]
1200    fn test_similarity_minimal() {
1201        let cli = parse_args(&["similarity", "text one", "text two"]).unwrap();
1202
1203        match cli.command {
1204            Commands::Similarity {
1205                text1,
1206                text2,
1207                model,
1208                gpu,
1209                quiet,
1210            } => {
1211                assert_eq!(text1, "text one");
1212                assert_eq!(text2, "text two");
1213                assert_eq!(model, "minilm-l6-v2");
1214                assert!(!gpu);
1215                assert!(!quiet);
1216            }
1217            _ => panic!("Expected Similarity command"),
1218        }
1219    }
1220
1221    #[test]
1222    fn test_model_list_defaults() {
1223        let cli = parse_args(&["model", "list"]).unwrap();
1224
1225        match cli.command {
1226            Commands::Model {
1227                action:
1228                    ModelCommands::List {
1229                        arch,
1230                        task,
1231                        downloaded,
1232                    },
1233            } => {
1234                assert!(arch.is_none());
1235                assert!(task.is_none());
1236                assert!(!downloaded);
1237            }
1238            _ => panic!("Expected Model List command"),
1239        }
1240    }
1241
1242    #[test]
1243    fn test_model_list_with_filters() {
1244        let cli = parse_args(&[
1245            "model",
1246            "list",
1247            "--arch",
1248            "bert",
1249            "--task",
1250            "embedding",
1251            "--downloaded",
1252        ])
1253        .unwrap();
1254
1255        match cli.command {
1256            Commands::Model {
1257                action:
1258                    ModelCommands::List {
1259                        arch,
1260                        task,
1261                        downloaded,
1262                    },
1263            } => {
1264                assert_eq!(arch, Some("bert".to_string()));
1265                assert_eq!(task, Some("embedding".to_string()));
1266                assert!(downloaded);
1267            }
1268            _ => panic!("Expected Model List command"),
1269        }
1270    }
1271
1272    #[test]
1273    fn test_model_download() {
1274        let cli = parse_args(&["model", "download", "minilm-l6-v2"]).unwrap();
1275
1276        match cli.command {
1277            Commands::Model {
1278                action: ModelCommands::Download { name, gguf, quiet },
1279            } => {
1280                assert_eq!(name, "minilm-l6-v2");
1281                assert!(!gguf);
1282                assert!(!quiet);
1283            }
1284            _ => panic!("Expected Model Download command"),
1285        }
1286    }
1287
1288    #[test]
1289    fn test_model_download_gguf() {
1290        let cli = parse_args(&["model", "download", "llama3.2-1b", "--gguf"]).unwrap();
1291
1292        match cli.command {
1293            Commands::Model {
1294                action: ModelCommands::Download { name, gguf, .. },
1295            } => {
1296                assert_eq!(name, "llama3.2-1b");
1297                assert!(gguf);
1298            }
1299            _ => panic!("Expected Model Download command"),
1300        }
1301    }
1302
1303    #[test]
1304    fn test_model_info() {
1305        let cli = parse_args(&["model", "info", "phi3.5-mini"]).unwrap();
1306
1307        match cli.command {
1308            Commands::Model {
1309                action: ModelCommands::Info { name },
1310            } => {
1311                assert_eq!(name, "phi3.5-mini");
1312            }
1313            _ => panic!("Expected Model Info command"),
1314        }
1315    }
1316
1317    #[test]
1318    fn test_model_remove() {
1319        let cli = parse_args(&["model", "remove", "old-model"]).unwrap();
1320
1321        match cli.command {
1322            Commands::Model {
1323                action: ModelCommands::Remove { name },
1324            } => {
1325                assert_eq!(name, "old-model");
1326            }
1327            _ => panic!("Expected Model Remove command"),
1328        }
1329    }
1330
1331    #[test]
1332    fn test_model_search() {
1333        let cli = parse_args(&["model", "search", "llama"]).unwrap();
1334
1335        match cli.command {
1336            Commands::Model {
1337                action: ModelCommands::Search { query },
1338            } => {
1339                assert_eq!(query, "llama");
1340            }
1341            _ => panic!("Expected Model Search command"),
1342        }
1343    }
1344
1345    #[test]
1346    fn test_index_create_minimal() {
1347        let cli = parse_args(&["index", "create", "output.idx"]).unwrap();
1348
1349        match cli.command {
1350            Commands::Index {
1351                action:
1352                    IndexCommands::Create {
1353                        output,
1354                        inputs,
1355                        chunk_size,
1356                        chunk_overlap,
1357                        model,
1358                        ..
1359                    },
1360            } => {
1361                assert_eq!(output, "output.idx");
1362                assert!(inputs.is_empty());
1363                assert_eq!(chunk_size, 512);
1364                assert_eq!(chunk_overlap, 100);
1365                assert_eq!(model, "minilm-l6-v2");
1366            }
1367            _ => panic!("Expected Index Create command"),
1368        }
1369    }
1370
1371    #[test]
1372    fn test_index_create_with_inputs() {
1373        let cli = parse_args(&[
1374            "index",
1375            "create",
1376            "out.idx",
1377            "file1.txt",
1378            "file2.txt",
1379            "dir/",
1380        ])
1381        .unwrap();
1382
1383        match cli.command {
1384            Commands::Index {
1385                action: IndexCommands::Create { inputs, .. },
1386            } => {
1387                assert_eq!(inputs.len(), 3);
1388                assert_eq!(inputs[0], "file1.txt");
1389                assert_eq!(inputs[1], "file2.txt");
1390                assert_eq!(inputs[2], "dir/");
1391            }
1392            _ => panic!("Expected Index Create command"),
1393        }
1394    }
1395
1396    #[test]
1397    fn test_index_create_with_options() {
1398        let cli = parse_args(&[
1399            "index",
1400            "create",
1401            "out.idx",
1402            "--chunk-size",
1403            "500",
1404            "--chunk-overlap",
1405            "100",
1406            "-m",
1407            "nomic-embed-text",
1408            "--gpu",
1409            "-q",
1410        ])
1411        .unwrap();
1412
1413        match cli.command {
1414            Commands::Index {
1415                action:
1416                    IndexCommands::Create {
1417                        chunk_size,
1418                        chunk_overlap,
1419                        model,
1420                        gpu,
1421                        quiet,
1422                        ..
1423                    },
1424            } => {
1425                assert_eq!(chunk_size, 500);
1426                assert_eq!(chunk_overlap, 100);
1427                assert_eq!(model, "nomic-embed-text");
1428                assert!(gpu);
1429                assert!(quiet);
1430            }
1431            _ => panic!("Expected Index Create command"),
1432        }
1433    }
1434
1435    #[test]
1436    fn test_index_add() {
1437        let cli = parse_args(&["index", "add", "existing.idx", "newfile.txt"]).unwrap();
1438
1439        match cli.command {
1440            Commands::Index {
1441                action:
1442                    IndexCommands::Add {
1443                        index_path, inputs, ..
1444                    },
1445            } => {
1446                assert_eq!(index_path, "existing.idx");
1447                assert_eq!(inputs, vec!["newfile.txt".to_string()]);
1448            }
1449            _ => panic!("Expected Index Add command"),
1450        }
1451    }
1452
1453    #[test]
1454    fn test_index_info() {
1455        let cli = parse_args(&["index", "info", "my.idx"]).unwrap();
1456
1457        match cli.command {
1458            Commands::Index {
1459                action: IndexCommands::Info { index_path },
1460            } => {
1461                assert_eq!(index_path, "my.idx");
1462            }
1463            _ => panic!("Expected Index Info command"),
1464        }
1465    }
1466
1467    #[test]
1468    fn test_verbose_zero() {
1469        let cli = parse_args(&["generate"]).unwrap();
1470        assert_eq!(cli.verbose, 0);
1471    }
1472
1473    #[test]
1474    fn test_verbose_one() {
1475        let cli = parse_args(&["-v", "generate"]).unwrap();
1476        assert_eq!(cli.verbose, 1);
1477    }
1478
1479    #[test]
1480    fn test_verbose_two() {
1481        let cli = parse_args(&["-vv", "generate"]).unwrap();
1482        assert_eq!(cli.verbose, 2);
1483    }
1484
1485    #[test]
1486    fn test_verbose_three() {
1487        let cli = parse_args(&["-vvv", "generate"]).unwrap();
1488        assert_eq!(cli.verbose, 3);
1489    }
1490
1491    #[test]
1492    fn test_verbose_long_form() {
1493        let cli = parse_args(&["--verbose", "--verbose", "generate"]).unwrap();
1494        assert_eq!(cli.verbose, 2);
1495    }
1496
1497    #[test]
1498    fn test_verbose_after_command() {
1499        // Global flag can come after command
1500        let cli = parse_args(&["generate", "-v"]).unwrap();
1501        assert_eq!(cli.verbose, 1);
1502    }
1503
1504    #[test]
1505    fn test_missing_command() {
1506        let result = parse_args(&[]);
1507        assert!(result.is_err());
1508    }
1509
1510    #[test]
1511    fn test_unknown_command() {
1512        let result = parse_args(&["unknown"]);
1513        assert!(result.is_err());
1514    }
1515
1516    #[test]
1517    fn test_missing_required_arg() {
1518        // transcribe requires a file
1519        let result = parse_args(&["transcribe"]);
1520        assert!(result.is_err());
1521    }
1522
1523    #[test]
1524    fn test_invalid_number() {
1525        let result = parse_args(&["generate", "-n", "not_a_number"]);
1526        assert!(result.is_err());
1527    }
1528
1529    #[test]
1530    fn test_invalid_float() {
1531        let result = parse_args(&["generate", "-t", "not_a_float"]);
1532        assert!(result.is_err());
1533    }
1534
1535    #[test]
1536    fn test_rerank_minimal() {
1537        let cli = parse_args(&["rerank", "my query"]).unwrap();
1538
1539        match cli.command {
1540            Commands::Rerank {
1541                query,
1542                documents,
1543                model,
1544                top_k,
1545                format,
1546                ..
1547            } => {
1548                assert_eq!(query, "my query");
1549                assert!(documents.is_empty());
1550                assert_eq!(model, "minilm-l6-v2-cross-encoder");
1551                assert!(top_k.is_none());
1552                assert_eq!(format, "text");
1553            }
1554            _ => panic!("Expected Rerank command"),
1555        }
1556    }
1557
1558    #[test]
1559    fn test_rerank_with_documents() {
1560        let cli = parse_args(&["rerank", "query", "doc1", "doc2", "doc3"]).unwrap();
1561
1562        match cli.command {
1563            Commands::Rerank {
1564                query, documents, ..
1565            } => {
1566                assert_eq!(query, "query");
1567                assert_eq!(documents.len(), 3);
1568            }
1569            _ => panic!("Expected Rerank command"),
1570        }
1571    }
1572
1573    #[test]
1574    fn test_rerank_with_top_k() {
1575        let cli = parse_args(&["rerank", "query", "-k", "5"]).unwrap();
1576
1577        match cli.command {
1578            Commands::Rerank { top_k, .. } => {
1579                assert_eq!(top_k, Some(5));
1580            }
1581            _ => panic!("Expected Rerank command"),
1582        }
1583    }
1584
1585    #[test]
1586    fn test_summarize_defaults() {
1587        let cli = parse_args(&["summarize"]).unwrap();
1588
1589        match cli.command {
1590            Commands::Summarize {
1591                input,
1592                model,
1593                min_length,
1594                max_length,
1595                num_beams,
1596                ..
1597            } => {
1598                assert!(input.is_none());
1599                assert_eq!(model, "distilbart-cnn");
1600                assert!(min_length.is_none());
1601                assert!(max_length.is_none());
1602                assert!(num_beams.is_none());
1603            }
1604            _ => panic!("Expected Summarize command"),
1605        }
1606    }
1607
1608    #[test]
1609    fn test_summarize_with_options() {
1610        let cli = parse_args(&[
1611            "summarize",
1612            "--input",
1613            "input.txt",
1614            "--min-length",
1615            "50",
1616            "--max-length",
1617            "200",
1618            "--num-beams",
1619            "4",
1620            "--length-penalty",
1621            "1.5",
1622        ])
1623        .unwrap();
1624
1625        match cli.command {
1626            Commands::Summarize {
1627                input,
1628                min_length,
1629                max_length,
1630                num_beams,
1631                length_penalty,
1632                ..
1633            } => {
1634                assert_eq!(input, Some("input.txt".to_string()));
1635                assert_eq!(min_length, Some(50));
1636                assert_eq!(max_length, Some(200));
1637                assert_eq!(num_beams, Some(4));
1638                assert_eq!(length_penalty, Some(1.5));
1639            }
1640            _ => panic!("Expected Summarize command"),
1641        }
1642    }
1643
1644    #[test]
1645    fn test_translate_defaults() {
1646        let cli = parse_args(&["translate"]).unwrap();
1647
1648        match cli.command {
1649            Commands::Translate {
1650                input,
1651                model,
1652                src,
1653                dst,
1654                ..
1655            } => {
1656                assert!(input.is_none());
1657                assert_eq!(model, None);
1658                assert!(src.is_none());
1659                assert!(dst.is_none());
1660            }
1661            _ => panic!("Expected Translate command"),
1662        }
1663    }
1664
1665    #[test]
1666    fn embed_normalizes_unless_told_not_to() {
1667        let flag = |args: &[&str]| match parse_args(args).unwrap().command {
1668            Commands::Embed { no_normalize, .. } => no_normalize,
1669            _ => panic!("Expected Embed command"),
1670        };
1671        assert!(!flag(&["embed", "hello"]));
1672        assert!(!flag(&["embed", "--normalize", "hello"]));
1673        assert!(flag(&["embed", "--no-normalize", "hello"]));
1674        assert!(parse_args(&["embed", "--normalize", "--no-normalize", "hello"]).is_err());
1675    }
1676
1677    #[test]
1678    fn test_translate_with_languages() {
1679        let cli = parse_args(&["translate", "--src", "en", "--dst", "is"]).unwrap();
1680
1681        match cli.command {
1682            Commands::Translate { src, dst, .. } => {
1683                assert_eq!(src, Some("en".to_string()));
1684                assert_eq!(dst, Some("is".to_string()));
1685            }
1686            _ => panic!("Expected Translate command"),
1687        }
1688    }
1689    #[test]
1690    fn test_transcribe_minimal() {
1691        let cli = parse_args(&["transcribe", "audio.wav"]).unwrap();
1692
1693        match cli.command {
1694            Commands::Transcribe {
1695                file,
1696                model,
1697                language,
1698                ..
1699            } => {
1700                assert_eq!(file, "audio.wav");
1701                assert_eq!(model, "whisper-small");
1702                assert!(language.is_none());
1703            }
1704            _ => panic!("Expected Transcribe command"),
1705        }
1706    }
1707
1708    #[test]
1709    fn test_classify_with_model() {
1710        let cli = parse_args(&["classify", "i hate mondays", "--model", "toxic-bert"]).unwrap();
1711        match cli.command {
1712            Commands::Classify { input, model, .. } => {
1713                assert_eq!(input, vec!["i hate mondays".to_string()]);
1714                assert_eq!(model, "toxic-bert");
1715            }
1716            _ => panic!("Expected Classify command"),
1717        }
1718    }
1719
1720    #[test]
1721    fn test_transcribe_with_options() {
1722        let cli = parse_args(&[
1723            "transcribe",
1724            "audio.mp3",
1725            "-m",
1726            "whisper-large-v3",
1727            "--language",
1728            "is",
1729        ])
1730        .unwrap();
1731
1732        match cli.command {
1733            Commands::Transcribe {
1734                file,
1735                model,
1736                language,
1737                ..
1738            } => {
1739                assert_eq!(file, "audio.mp3");
1740                assert_eq!(model, "whisper-large-v3");
1741                assert_eq!(language, Some("is".to_string()));
1742            }
1743            _ => panic!("Expected Transcribe command"),
1744        }
1745    }
1746}
1747
1748mod send_sync_tests {
1749    use kjarni::{
1750        Classifier, Embedder, Indexer, Reranker, Searcher, chat::Chat, generator::Generator,
1751    };
1752    // Compile time verificatio
1753    const _: () = {
1754        const fn assert_send<T: Send>() {}
1755        const fn assert_sync<T: Sync>() {}
1756        assert_send::<Embedder>();
1757        assert_sync::<Embedder>();
1758
1759        assert_send::<Indexer>();
1760        assert_sync::<Indexer>();
1761
1762        assert_send::<Searcher>();
1763        assert_sync::<Searcher>();
1764
1765        assert_send::<Reranker>();
1766        assert_sync::<Reranker>();
1767
1768        assert_send::<Generator>();
1769        assert_sync::<Generator>();
1770
1771        assert_send::<Chat>();
1772        assert_sync::<Chat>();
1773
1774        assert_send::<Classifier>();
1775        assert_sync::<Classifier>();
1776    };
1777}