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