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

fix(download): loose download host check - when TABBY_DOWNLOAD_HOST i… #2183

Merged
merged 2 commits into from
May 20, 2024
Merged
Changes from all commits
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
26 changes: 10 additions & 16 deletions crates/tabby-download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
};
use tracing::{info, warn};

fn download_host() -> String {
std::env::var("TABBY_DOWNLOAD_HOST").unwrap_or("huggingface.co".to_owned())
fn select_by_download_host(url: &String) -> bool {
if let Ok(host) = std::env::var("TABBY_DOWNLOAD_HOST") {
url.contains(&host)

Check warning on line 19 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L17-L19

Added lines #L17 - L19 were not covered by tests
} else {
true

Check warning on line 21 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L21

Added line #L21 was not covered by tests
}
}

async fn download_model_impl(
Expand Down Expand Up @@ -50,18 +54,13 @@
return download_split_model(model_info, &model_path).await;
}

let registry = download_host();
let Some(model_url) = model_info
.urls
.iter()
.flatten()
.find(|x| x.contains(&registry))
.find(|x| select_by_download_host(x))

Check warning on line 61 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L61

Added line #L61 was not covered by tests
else {
return Err(anyhow!(
"Invalid mirror <{}> for model urls: {:?}",
registry,
model_info.urls
));
return Err(anyhow!("No valid url for model <{}>", model_info.name));

Check warning on line 63 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L63

Added line #L63 was not covered by tests
};

let strategy = ExponentialBackoff::from_millis(100).map(jitter).take(2);
Expand All @@ -79,17 +78,12 @@
}
let mut paths = vec![];
let partition_urls = model_info.partition_urls.clone().unwrap_or_default();
let mirror = download_host();

let Some(urls) = partition_urls
.iter()
.find(|urls| urls.iter().all(|url| url.contains(&mirror)))
.find(|urls| urls.iter().all(select_by_download_host))

Check warning on line 84 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L84

Added line #L84 was not covered by tests
else {
return Err(anyhow!(
"Invalid mirror <{}> for model urls: {:?}",
mirror,
partition_urls
));
return Err(anyhow!("No valid url for model <{}>", model_info.name));

Check warning on line 86 in crates/tabby-download/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/tabby-download/src/lib.rs#L86

Added line #L86 was not covered by tests
};

for (index, url) in urls.iter().enumerate() {
Expand Down
Loading