feat(cli): add direct model inference via new run subcommand

- Add `aha run` CLI subcommand for direct model inference without HTTP service
- Support multiple models including Qwen series, OCR models, ASR models, and voice generation
- Implement input/output handling with file path support and auto-generation
- Add comprehensive documentation in CLI_USAGE.md with examples
- Include performance timing for model loading and inference operations
- Add macOS build target to Makefile with Metal support
```
This commit is contained in:
XiaoYang
2026-01-21 18:41:11 +08:00
parent 861c411ba2
commit f010087e97
18 changed files with 899 additions and 8 deletions
+52
View File
@@ -0,0 +1,52 @@
//! Qwen3VL-2B exec implementation for CLI `run` subcommand
use crate::exec::ExecModel;
use crate::models::{GenerateModel, qwen3vl::generate::Qwen3VLGenerateModel};
use anyhow::{Ok, Result};
use std::time::Instant;
pub struct Qwen3vlExec;
impl ExecModel for Qwen3vlExec {
fn run(input: &str, output: Option<&str>, weight_path: &str) -> Result<()> {
let target_text = if input.starts_with("file://") {
let path = &input[7..];
std::fs::read_to_string(path)?
} else {
input.to_string()
};
let i_start = Instant::now();
let mut model = Qwen3VLGenerateModel::init(weight_path, None, None)?;
let i_duration = i_start.elapsed();
println!("Time elapsed in load model is: {:?}", i_duration);
let message = format!(
r#"{{
"model": "qwen3vl",
"messages": [
{{
"role": "user",
"content": "{}"
}}
]
}}"#,
target_text.replace('"', "\\\"")
);
let mes = serde_json::from_str(&message)?;
let i_start = Instant::now();
let result = model.generate(mes)?;
let i_duration = i_start.elapsed();
println!("Time elapsed in generate is: {:?}", i_duration);
println!("Result: {:?}", result);
if let Some(out) = output {
std::fs::write(out, format!("{:?}", result))?;
println!("Output saved to: {}", out);
}
Ok(())
}
}