1use std::path::PathBuf;
2
3use crate::cli::LlmAction;
4use crate::llm_lifecycle;
5use crate::llm_testing;
6
7pub async fn handle(action: &LlmAction) -> Result<(), Box<dyn std::error::Error>> {
8 let vault = |opt: &Option<PathBuf>| {
9 opt.clone()
10 .unwrap_or_else(llm_lifecycle::default_vault_path)
11 };
12 match action {
13 LlmAction::List { vault_path } => {
14 llm_lifecycle::run_list(&vault(vault_path))?;
15 }
16 LlmAction::Duplicates { vault_path } => {
17 llm_lifecycle::run_duplicate_audit(&vault(vault_path))?;
18 }
19 LlmAction::Load { model, vault_path } => {
20 llm_lifecycle::run_load(&vault(vault_path), model)?;
21 }
22 LlmAction::Status => {
23 llm_lifecycle::run_status()?;
24 }
25 LlmAction::Eval {
26 prompt,
27 orchestrated,
28 stream,
29 lora,
30 } => {
31 if let Some(l) = lora {
32 println!("Multiplexing LoRA adapter from {:?}", l);
33 }
34 llm_lifecycle::run_eval(prompt, *orchestrated, *stream)?;
35 }
36 LlmAction::Evict { model_id } => {
37 llm_lifecycle::run_evict(model_id)?;
38 }
39 LlmAction::Test {
40 vault_path,
41 models,
42 quantization,
43 verbose,
44 } => {
45 llm_testing::run_test_models(
46 vault_path.clone(),
47 models.clone(),
48 quantization.clone(),
49 *verbose,
50 )?;
51 }
52 LlmAction::Validate { vault_path, strict } => {
53 llm_testing::run_validate_models(vault_path.clone(), *strict)?;
54 }
55 LlmAction::ComprehensiveTest {
56 vault_path,
57 model,
58 verbose,
59 } => {
60 llm_testing::run_comprehensive_llm_test(vault_path.clone(), model.clone(), *verbose)?;
61 }
62 LlmAction::Benchmark {
63 vault_path,
64 models,
65 iterations,
66 warmup,
67 } => {
68 llm_testing::run_benchmark_models(
69 vault_path.clone(),
70 models.clone(),
71 *iterations,
72 *warmup,
73 )?;
74 }
75 LlmAction::Report {
76 vault_path,
77 output,
78 format,
79 } => {
80 llm_testing::run_generate_report(vault_path.clone(), output.clone(), format.clone())?;
81 }
82 LlmAction::Convert {
83 input,
84 out,
85 page_log2,
86 layout,
87 } => {
88 llm_testing::run_convert_gguf_to_p64(input, out, *page_log2, layout)?;
89 }
90 LlmAction::Optimize {
91 input,
92 out,
93 skip_passport,
94 } => {
95 llm_testing::run_optimize_pipeline(input, out.clone(), *skip_passport)?;
96 }
97 LlmAction::Passport {
98 reprobe,
99 gemv_n,
100 cache,
101 apply_env_hint,
102 decode_proxy,
103 decode_proxy_tokens,
104 } => {
105 llm_testing::run_hardware_passport(
106 *reprobe,
107 *gemv_n,
108 cache.clone(),
109 *apply_env_hint,
110 decode_proxy.clone(),
111 *decode_proxy_tokens,
112 )?;
113 }
114 LlmAction::DecodeProxy { model, tokens } => {
115 llm_testing::run_decode_proxy(model, *tokens)?;
116 }
117 LlmAction::RawDecodeBench {
118 model,
119 steps,
120 warmups,
121 runs,
122 quantization,
123 prompt,
124 target_prompt_tokens,
125 retain_artifacts,
126 } => {
127 crate::llm_raw_bench::run(crate::llm_raw_bench::CommandConfig {
128 model,
129 steps: *steps,
130 warmups: *warmups,
131 runs: *runs,
132 quantization,
133 prompt,
134 target_prompt_tokens: *target_prompt_tokens,
135 retain_artifacts: retain_artifacts.as_deref(),
136 })?;
137 }
138 LlmAction::Mode { name } => {
139 llm_testing::run_inference_mode(name.as_deref())?;
140 }
141 LlmAction::PathSelect { reprobe, apply } => {
142 llm_testing::run_path_select(*reprobe, *apply)?;
143 }
144 LlmAction::Profile { name } => {
145 llm_testing::run_app_profile(name.as_deref())?;
146 }
147 LlmAction::Lab {
148 action,
149 model,
150 tokens,
151 n_in,
152 n_out,
153 gemv_n,
154 out,
155 hours,
156 max_generations,
157 ollama_model,
158 ollama_url,
159 no_ollama,
160 } => {
161 llm_testing::run_lab(
162 action,
163 model.as_deref(),
164 *tokens,
165 *n_in,
166 *n_out,
167 *gemv_n,
168 out.as_deref(),
169 *hours,
170 *max_generations,
171 ollama_model.as_deref(),
172 ollama_url,
173 *no_ollama,
174 )?;
175 }
176 LlmAction::Ground { prompt, answer } => {
177 llm_testing::run_ground_check(prompt, answer)?;
178 }
179 LlmAction::SeedGrounding => {
180 llm_testing::run_seed_grounding()?;
181 }
182 LlmAction::CudaTcBench { side } => {
183 llm_testing::run_cuda_tc_microbench(*side)?;
184 }
185 LlmAction::Explore {
186 input,
187 out,
188 tokens,
189 layouts,
190 skip_convert,
191 sweep_ffn_f16,
192 modes,
193 } => {
194 llm_testing::run_explore_pipeline(
195 input,
196 out.clone(),
197 *tokens,
198 layouts,
199 *skip_convert,
200 *sweep_ffn_f16,
201 modes.as_deref(),
202 )?;
203 }
204 }
205 Ok(())
206}