Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tabby): Add model subcommand #1669

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion crates/tabby/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
/// Run scheduler progress for cron jobs integrating external code repositories.
Scheduler(SchedulerArgs),

/// Manage local models
/// Install, list, and delete models for local use
boxbeam marked this conversation as resolved.
Show resolved Hide resolved
#[command(subcommand)]
Model(model::ModelArgs),

Expand Down Expand Up @@ -178,7 +178,7 @@
Commands::WorkerChat(ref args) => {
worker::main(tabby_webserver::public::WorkerKind::Chat, args).await
}
Commands::Model(args) => model::main(args).await,

Check warning on line 181 in crates/tabby/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/main.rs#L181

Added line #L181 was not covered by tests
}

opentelemetry::global::shutdown_tracer_provider();
Expand Down
5 changes: 4 additions & 1 deletion crates/tabby/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
use clap::Subcommand;
use tabby_common::registry::{parse_model_id, ModelRegistry, DEFAULT_MODEL_REGISTRY_NAME};

#[derive(Subcommand)]

Check warning on line 4 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L4

Added line #L4 was not covered by tests
pub enum ModelArgs {
#[clap(alias = "rm")]
boxbeam marked this conversation as resolved.
Show resolved Hide resolved
/// Delete a locally-downloaded model
Delete { model: String },

Check warning on line 8 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L8

Added line #L8 was not covered by tests
#[clap(alias = "ls")]
/// List the available models specified by a registry
List { registry: Option<String> },
#[clap(alias = "get")]
#[clap(alias = "get", alias = "install")]
/// Download a model by [registry/]name
boxbeam marked this conversation as resolved.
Show resolved Hide resolved
Download { model: String },

Check warning on line 14 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L14

Added line #L14 was not covered by tests
}

pub async fn main(args: ModelArgs) {
match args {
ModelArgs::Delete { model } => delete_model(&model).await,
ModelArgs::List { registry } => list_models(registry).await,
ModelArgs::Download { model } => download_model(&model).await,

Check warning on line 21 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L17-L21

Added lines #L17 - L21 were not covered by tests
}
}

Check warning on line 23 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L23

Added line #L23 was not covered by tests

async fn delete_model(model: &str) {
let (registry, name) = parse_model_id(model);
let registry = ModelRegistry::new(registry).await;
let path = registry.get_model_dir(name);
if !path.exists() {
println!("Model {model} is not downloaded");
return;
}
tokio::fs::remove_dir_all(path).await.unwrap();
println!("Model {model} removed");
}

Check warning on line 35 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L25-L35

Added lines #L25 - L35 were not covered by tests

async fn list_models(registry: Option<String>) {
let registry = registry.as_deref().unwrap_or(DEFAULT_MODEL_REGISTRY_NAME);
let registry = ModelRegistry::new(registry).await;
for model in &registry.models {
let installed = registry
.get_model_path(&model.name)
.exists()
.then_some("[Installed]")
.unwrap_or_default();
println!("{} {installed}", model.name);
}
}

Check warning on line 48 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L37-L48

Added lines #L37 - L48 were not covered by tests

async fn download_model(model: &str) {
let (registry, name) = parse_model_id(model);
let registry = ModelRegistry::new(registry).await;
if registry.get_model_dir(name).exists() {
println!("Model {model} already downloaded");
return;
}
tabby_download::download_model(model, true).await
}

Check warning on line 58 in crates/tabby/src/model.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby/src/model.rs#L50-L58

Added lines #L50 - L58 were not covered by tests
Loading