refactor: extract download into tabby-download (#195)
* refactor: extract download into tabby-download * remove unused depsdocs-add-demo
parent
b1f910b727
commit
e8a33312bb
|
|
@ -691,19 +691,6 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "env_logger"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
|
|
||||||
dependencies = [
|
|
||||||
"humantime",
|
|
||||||
"is-terminal",
|
|
||||||
"log",
|
|
||||||
"regex",
|
|
||||||
"termcolor",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|
@ -1012,12 +999,6 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "humantime"
|
|
||||||
version = "2.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.14.26"
|
version = "0.14.26"
|
||||||
|
|
@ -2253,19 +2234,13 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
|
||||||
name = "tabby"
|
name = "tabby"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
|
||||||
"axum",
|
"axum",
|
||||||
"clap",
|
"clap",
|
||||||
"ctranslate2-bindings",
|
"ctranslate2-bindings",
|
||||||
"env_logger",
|
|
||||||
"futures-util",
|
|
||||||
"hyper",
|
"hyper",
|
||||||
"indicatif 0.17.3",
|
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
@ -2273,6 +2248,7 @@ dependencies = [
|
||||||
"strfmt",
|
"strfmt",
|
||||||
"strum",
|
"strum",
|
||||||
"tabby-common",
|
"tabby-common",
|
||||||
|
"tabby-download",
|
||||||
"tabby-scheduler",
|
"tabby-scheduler",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tower",
|
"tower",
|
||||||
|
|
@ -2294,6 +2270,19 @@ dependencies = [
|
||||||
"serdeconv",
|
"serdeconv",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tabby-download"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"futures-util",
|
||||||
|
"indicatif 0.17.3",
|
||||||
|
"reqwest",
|
||||||
|
"serde",
|
||||||
|
"serdeconv",
|
||||||
|
"tabby-common",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tabby-scheduler"
|
name = "tabby-scheduler"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ members = [
|
||||||
"crates/tabby",
|
"crates/tabby",
|
||||||
"crates/tabby-common",
|
"crates/tabby-common",
|
||||||
"crates/tabby-scheduler",
|
"crates/tabby-scheduler",
|
||||||
|
"crates/tabby-download",
|
||||||
"crates/ctranslate2-bindings",
|
"crates/ctranslate2-bindings",
|
||||||
"crates/rust-cxx-cmake-bridge",
|
"crates/rust-cxx-cmake-bridge",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "tabby-download"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tabby-common = { path = "../tabby-common" }
|
||||||
|
indicatif = "0.17.3"
|
||||||
|
futures-util = "0.3.28"
|
||||||
|
reqwest = { version = "0.11.18", features = ["stream", "json"] }
|
||||||
|
anyhow = "1.0.71"
|
||||||
|
serde = { workspace = true }
|
||||||
|
serdeconv = { workspace = true }
|
||||||
|
|
@ -4,31 +4,13 @@ use std::cmp;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
use clap::Args;
|
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use tabby_common::path::ModelDir;
|
use tabby_common::path::ModelDir;
|
||||||
|
|
||||||
use cache_info::CacheInfo;
|
use cache_info::CacheInfo;
|
||||||
|
|
||||||
#[derive(Args)]
|
|
||||||
pub struct DownloadArgs {
|
|
||||||
/// model id to fetch.
|
|
||||||
#[clap(long)]
|
|
||||||
model: String,
|
|
||||||
|
|
||||||
/// If true, skip checking for remote model file.
|
|
||||||
#[clap(long, default_value_t = false)]
|
|
||||||
prefer_local_file: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn main(args: &DownloadArgs) {
|
|
||||||
download_model(&args.model, args.prefer_local_file).await;
|
|
||||||
info!("model '{}' is ready", args.model);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CacheInfo {
|
impl CacheInfo {
|
||||||
async fn download(&mut self, model_id: &str, path: &str, prefer_local_file: bool) {
|
async fn download(&mut self, model_id: &str, path: &str, prefer_local_file: bool) {
|
||||||
// Create url.
|
// Create url.
|
||||||
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
||||||
ctranslate2-bindings = { path = "../ctranslate2-bindings" }
|
ctranslate2-bindings = { path = "../ctranslate2-bindings" }
|
||||||
tabby-common = { path = "../tabby-common" }
|
tabby-common = { path = "../tabby-common" }
|
||||||
tabby-scheduler = { path = "../tabby-scheduler" }
|
tabby-scheduler = { path = "../tabby-scheduler" }
|
||||||
|
tabby-download = { path = "../tabby-download" }
|
||||||
axum = "0.6"
|
axum = "0.6"
|
||||||
hyper = { version = "0.14", features = ["full"] }
|
hyper = { version = "0.14", features = ["full"] }
|
||||||
tokio = { workspace = true, features = ["full"] }
|
tokio = { workspace = true, features = ["full"] }
|
||||||
|
|
@ -16,8 +17,6 @@ utoipa-swagger-ui = { version = "3.1", features = ["axum"] }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serdeconv = { workspace = true }
|
serdeconv = { workspace = true }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
env_logger = "0.10.0"
|
|
||||||
log = "0.4"
|
|
||||||
tower-http = { version = "0.4.0", features = ["cors"] }
|
tower-http = { version = "0.4.0", features = ["cors"] }
|
||||||
clap = { version = "4.3.0", features = ["derive"] }
|
clap = { version = "4.3.0", features = ["derive"] }
|
||||||
regex = "1.8.3"
|
regex = "1.8.3"
|
||||||
|
|
@ -25,10 +24,6 @@ lazy_static = { workspace = true }
|
||||||
rust-embed = "6.6.1"
|
rust-embed = "6.6.1"
|
||||||
mime_guess = "2.0.4"
|
mime_guess = "2.0.4"
|
||||||
strum = { version = "0.24", features = ["derive"] }
|
strum = { version = "0.24", features = ["derive"] }
|
||||||
reqwest = { version = "0.11.18", features = ["stream", "json"] }
|
|
||||||
indicatif = "0.17.3"
|
|
||||||
futures-util = "0.3.28"
|
|
||||||
anyhow = "1.0.71"
|
|
||||||
strfmt = "0.2.4"
|
strfmt = "0.2.4"
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
tracing-subscriber = { workspace = true }
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
use clap::Args;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct DownloadArgs {
|
||||||
|
/// model id to fetch.
|
||||||
|
#[clap(long)]
|
||||||
|
model: String,
|
||||||
|
|
||||||
|
/// If true, skip checking for remote model file.
|
||||||
|
#[clap(long, default_value_t = false)]
|
||||||
|
prefer_local_file: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn main(args: &DownloadArgs) {
|
||||||
|
tabby_download::download_model(&args.model, args.prefer_local_file).await;
|
||||||
|
info!("model '{}' is ready", args.model);
|
||||||
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ pub async fn main(args: &ServeArgs) {
|
||||||
valid_args(args);
|
valid_args(args);
|
||||||
|
|
||||||
// Ensure model exists.
|
// Ensure model exists.
|
||||||
crate::download::download_model(&args.model, true).await;
|
tabby_download::download_model(&args.model, true).await;
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
|
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue