From ca160510650387c6117f78785075d501b1dd0f3f Mon Sep 17 00:00:00 2001 From: XiaoYang Date: Fri, 6 Feb 2026 17:54:15 +0800 Subject: [PATCH] feat(cli): make weight path optional with default location Change --weight-path argument from required to optional in both serv and run subcommands. When not specified, it defaults to ~/.aha/{model_id}. Add get_default_weight_path function to handle the default path resolution. Update help text to reflect the optional nature of the weight path parameter. --- Makefile | 1 + src/main.rs | 35 +++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index a69a21e..3fe8d57 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ lint: help: @echo "Available commands:" @echo " build - Build the project" + @echo " build_mac - Build the project for macOS" @echo " test - Run tests" @echo " clean - Clean the project" @echo " fmt - Format the code" diff --git a/src/main.rs b/src/main.rs index 2a459c4..d6dada5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ struct Cli { enum Commands { /// Download model and start service (default) Cli(CliArgs), - /// Start service only (requires --weight-path) + /// Start service only (--weight-path is optional, defaults to ~/.aha/{model_id}) Serv(ServArgs), /// Download model only Download(DownloadArgs), @@ -101,9 +101,9 @@ struct ServArgs { #[command(flatten)] common: CommonArgs, - /// Local model weight path (required) - #[arg(long, required = true)] - weight_path: String, + /// Local model weight path (defaults to ~/.aha/{model_id} if not specified) + #[arg(long)] + weight_path: Option, } /// Arguments for the 'download' subcommand (download only) @@ -137,9 +137,17 @@ struct RunArgs { #[arg(short, long)] output: Option, - /// Local model weight path (required) - #[arg(long, required = true)] - weight_path: String, + /// Local model weight path (defaults to ~/.aha/{model_id} if not specified) + #[arg(long)] + weight_path: Option, +} + +/// Get the default weight path for a given model +/// Returns ~/.aha/{model_id} e.g., ~/.aha/OpenBMB/VoxCPM1.5 +fn get_default_weight_path(model: WhichModel) -> String { + let model_id = get_model_id(model); + let save_dir = get_default_save_dir().expect("Failed to get home directory"); + format!("{}/{}", save_dir, model_id) } /// Get the ModelScope model ID for a given WhichModel variant @@ -239,7 +247,12 @@ async fn run_serv(args: ServArgs) -> anyhow::Result<()> { weight_path, } = args; - init(common.model, weight_path)?; + let model_path = match weight_path { + Some(path) => path, + None => get_default_weight_path(common.model), + }; + + init(common.model, model_path)?; start_http_server(common.address, common.port).await?; Ok(()) @@ -276,6 +289,12 @@ fn run_run(args: RunArgs) -> anyhow::Result<()> { weight_path, } = args; + // Use default weight path if not specified + let weight_path = match weight_path { + Some(path) => path, + None => get_default_weight_path(model), + }; + match model { WhichModel::MiniCPM4_0_5B => { use aha::exec::minicpm4::MiniCPM4Exec;