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.
This commit is contained in:
@@ -33,6 +33,7 @@ lint:
|
|||||||
help:
|
help:
|
||||||
@echo "Available commands:"
|
@echo "Available commands:"
|
||||||
@echo " build - Build the project"
|
@echo " build - Build the project"
|
||||||
|
@echo " build_mac - Build the project for macOS"
|
||||||
@echo " test - Run tests"
|
@echo " test - Run tests"
|
||||||
@echo " clean - Clean the project"
|
@echo " clean - Clean the project"
|
||||||
@echo " fmt - Format the code"
|
@echo " fmt - Format the code"
|
||||||
|
|||||||
+27
-8
@@ -50,7 +50,7 @@ struct Cli {
|
|||||||
enum Commands {
|
enum Commands {
|
||||||
/// Download model and start service (default)
|
/// Download model and start service (default)
|
||||||
Cli(CliArgs),
|
Cli(CliArgs),
|
||||||
/// Start service only (requires --weight-path)
|
/// Start service only (--weight-path is optional, defaults to ~/.aha/{model_id})
|
||||||
Serv(ServArgs),
|
Serv(ServArgs),
|
||||||
/// Download model only
|
/// Download model only
|
||||||
Download(DownloadArgs),
|
Download(DownloadArgs),
|
||||||
@@ -101,9 +101,9 @@ struct ServArgs {
|
|||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
common: CommonArgs,
|
common: CommonArgs,
|
||||||
|
|
||||||
/// Local model weight path (required)
|
/// Local model weight path (defaults to ~/.aha/{model_id} if not specified)
|
||||||
#[arg(long, required = true)]
|
#[arg(long)]
|
||||||
weight_path: String,
|
weight_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Arguments for the 'download' subcommand (download only)
|
/// Arguments for the 'download' subcommand (download only)
|
||||||
@@ -137,9 +137,17 @@ struct RunArgs {
|
|||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
output: Option<String>,
|
output: Option<String>,
|
||||||
|
|
||||||
/// Local model weight path (required)
|
/// Local model weight path (defaults to ~/.aha/{model_id} if not specified)
|
||||||
#[arg(long, required = true)]
|
#[arg(long)]
|
||||||
weight_path: String,
|
weight_path: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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
|
/// Get the ModelScope model ID for a given WhichModel variant
|
||||||
@@ -239,7 +247,12 @@ async fn run_serv(args: ServArgs) -> anyhow::Result<()> {
|
|||||||
weight_path,
|
weight_path,
|
||||||
} = args;
|
} = 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?;
|
start_http_server(common.address, common.port).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -276,6 +289,12 @@ fn run_run(args: RunArgs) -> anyhow::Result<()> {
|
|||||||
weight_path,
|
weight_path,
|
||||||
} = args;
|
} = 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 {
|
match model {
|
||||||
WhichModel::MiniCPM4_0_5B => {
|
WhichModel::MiniCPM4_0_5B => {
|
||||||
use aha::exec::minicpm4::MiniCPM4Exec;
|
use aha::exec::minicpm4::MiniCPM4Exec;
|
||||||
|
|||||||
Reference in New Issue
Block a user