Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 52 additions & 24 deletions src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use prettytable::{format, row, Table};

use crate::cli::{inspect, ls, rm};
use crate::downloader::huggingface::HuggingFaceDownloader;
use crate::downloader::Downloader;
use crate::downloader::{self, Provider};
use crate::registry::model_registry::ModelRegistry;
use crate::system::system_info::SystemInfo;
use crate::utils::format::{format_size_decimal, format_time_ago};
Expand All @@ -26,7 +25,7 @@
/// Download a model from a model provider
PULL(PullArgs),
/// Create and run a new model
RUN,
RUN(RunArgs),
Comment thread
kerthcet marked this conversation as resolved.
/// Stop one running model
STOP,
/// Remove one model
Expand All @@ -41,6 +40,22 @@
SERVE(ServeArgs),
}

#[derive(Parser)]
struct RunArgs {
/// Model name to run (e.g., inftyai/tiny-random-gpt2)
model: String,

/// Provider to download from if model not found
#[arg(
short = 'p',
long,
value_name = "model provider",
value_enum,
default_value = "huggingface"
)]
provider: Provider,
}
Comment thread
kerthcet marked this conversation as resolved.

#[derive(Parser)]
struct ServeArgs {
/// Model name to serve (e.g., inftyai/tiny-random-gpt2)
Expand Down Expand Up @@ -88,17 +103,9 @@
#[derive(Parser)]
struct InspectArgs {
/// Model name to inspect (e.g., inftyai/tiny-random-gpt2)
model: String,

Check warning on line 106 in src/cli/commands.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/PUMA/PUMA/src/cli/commands.rs
}

#[derive(Debug, Clone, Default, clap::ValueEnum)]
pub enum Provider {
#[default]
#[value(alias = "hf")]
Huggingface,
#[value(alias = "ms")]
Modelscope,
}

// Support commands like: pull, ls, run, ps, stop, rm, info, inspect, show.
pub async fn run(cli: Cli) {
Expand Down Expand Up @@ -171,22 +178,43 @@
table.printstd();
}

Commands::PULL(args) => match args.provider {
Provider::Huggingface => {
let downloader = HuggingFaceDownloader::new();
// Make sure to use lowercase for model name to ensure consistent caching and registry entries.
if let Err(e) = downloader.download_model(&args.model.to_lowercase()).await {
eprintln!("❌ Error downloading model: {}", e);
Commands::PULL(args) => {
if let Err(e) = downloader::download_model(&args.model, args.provider).await {
eprintln!("❌ Error: {}", e);
std::process::exit(1);
}
}

Commands::RUN(args) => {
let registry = ModelRegistry::new(None);

// Check if model exists
match registry.get_model(&args.model) {
Ok(Some(_)) => {
// Model exists, proceed
println!("Running model: {}", args.model);
// TODO: Implement actual model execution
println!("Model execution not yet implemented");
}
Comment thread
kerthcet marked this conversation as resolved.
Ok(None) => {
// Model not found, download it first
println!("Model '{}' not found locally. Downloading...", args.model);

if let Err(e) = downloader::download_model(&args.model, args.provider).await {
eprintln!("❌ Error: {}", e);
std::process::exit(1);
}

// Now run the model
println!("Running model: {}", args.model);
// TODO: Implement actual model execution
println!("Model execution not yet implemented");
}
Comment thread
kerthcet marked this conversation as resolved.
Err(e) => {
eprintln!("❌ Error checking model: {}", e);
std::process::exit(1);
}
}
Provider::Modelscope => {
println!("Downloading model from Modelscope...");
}
},

Commands::RUN => {
println!("Creating and running a new model...");
}

Commands::STOP => {
Expand Down
25 changes: 25 additions & 0 deletions src/downloader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@
pub trait Downloader {
async fn download_model(&self, name: &str) -> Result<(), DownloadError>;
}

/// Provider for downloading models
#[derive(Debug, Clone, Copy, Default, clap::ValueEnum)]
pub enum Provider {
#[default]
#[value(alias = "hf")]
Huggingface,
#[value(alias = "ms")]
Modelscope,
}

/// Download a model from the specified provider
pub async fn download_model(model_name: &str, provider: Provider) -> Result<(), DownloadError> {
match provider {
Provider::Huggingface => {
let downloader = huggingface::HuggingFaceDownloader::new();

Check warning on line 47 in src/downloader/mod.rs

View workflow job for this annotation

GitHub Actions / Lint

Diff in /home/runner/work/PUMA/PUMA/src/downloader/mod.rs
downloader.download_model(&model_name.to_lowercase()).await
}
Comment thread
kerthcet marked this conversation as resolved.
Provider::Modelscope => {
Err(DownloadError::ApiError(
"Modelscope provider not yet implemented".to_string(),
))
}
}
}
Loading