pub mod api;
pub mod client;
pub mod download;
pub mod oci;
pub mod progress;
pub mod pull;
pub mod transfer;
use std::path::PathBuf;
use std::time::Duration;
use anyhow::{anyhow, Context, Result};
use serde::Deserialize;
pub fn is_hf_host(server: &str) -> bool {
let host = server
.trim_start_matches("https://")
.trim_start_matches("http://")
.split('/')
.next()
.unwrap_or(server)
.to_ascii_lowercase();
matches!(
host.as_str(),
"hf.co" | "huggingface.co" | "www.huggingface.co"
)
}
pub fn endpoint() -> String {
endpoint_from(|var| std::env::var_os(var))
}
fn endpoint_from(env: impl Fn(&str) -> Option<std::ffi::OsString>) -> String {
endpoint_override(env, &["HF_ENDPOINT"]).unwrap_or_else(|| "https://huggingface.co".to_string())
}
fn endpoint_override(
env: impl Fn(&str) -> Option<std::ffi::OsString>,
vars: &[&str],
) -> Option<String> {
vars.iter()
.find_map(|var| {
env(var)
.and_then(|v| v.into_string().ok())
.filter(|v| !v.is_empty())
})
.map(|v| v.trim_end_matches('/').to_string())
}
fn process_env() -> (impl Fn(&str) -> Option<std::ffi::OsString>, Option<PathBuf>) {
(|var: &str| std::env::var_os(var), dirs::home_dir())
}
fn hf_home_from(
env: impl Fn(&str) -> Option<std::ffi::OsString>,
home: Option<PathBuf>,
) -> PathBuf {
crate::env_dir_from(&env, "HF_HOME").unwrap_or_else(|| {
crate::env_dir_from(&env, "XDG_CACHE_HOME")
.unwrap_or_else(|| home.unwrap_or_else(|| PathBuf::from(".")).join(".cache"))
.join("huggingface")
})
}
const DEFAULT_MAX_TRANSFER_STREAMS: usize = 4;
pub fn max_transfer_streams() -> usize {
parse_max_transfer_streams(std::env::var("LLMMAN_MAX_TRANSFER_STREAMS").ok().as_deref())
}
fn parse_max_transfer_streams(value: Option<&str>) -> usize {
match value.map(str::trim).and_then(|v| v.parse::<usize>().ok()) {
None => DEFAULT_MAX_TRANSFER_STREAMS,
Some(n) => n.max(1),
}
}
pub fn token_path() -> PathBuf {
let (env, home) = process_env();
token_path_from(env, home)
}
fn token_path_from(
env: impl Fn(&str) -> Option<std::ffi::OsString>,
home: Option<PathBuf>,
) -> PathBuf {
match crate::env_dir_from(&env, "HF_TOKEN_PATH") {
Some(path) => path,
None => hf_home_from(&env, home).join("token"),
}
}
fn legacy_token_path() -> Option<PathBuf> {
let (env, home) = process_env();
legacy_token_path_from(env, home)
}
fn legacy_token_path_from(
env: impl Fn(&str) -> Option<std::ffi::OsString>,
home: Option<PathBuf>,
) -> Option<PathBuf> {
if crate::env_dir_from(&env, "HF_TOKEN_PATH").is_some()
|| crate::env_dir_from(&env, "HF_HOME").is_some()
{
return None;
}
let legacy = home
.clone()
.unwrap_or_else(|| PathBuf::from("."))
.join(".cache")
.join("huggingface")
.join("token");
(legacy != token_path_from(&env, home)).then_some(legacy)
}
fn read_token_file(path: &std::path::Path, legacy: Option<&std::path::Path>) -> Option<String> {
match std::fs::read_to_string(path) {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
legacy.and_then(|legacy| std::fs::read_to_string(legacy).ok())
}
other => other.ok(),
}
}
pub fn token() -> Option<String> {
let (env, home) = process_env();
token_from(env, home)
}
fn token_from(
env: impl Fn(&str) -> Option<std::ffi::OsString>,
home: Option<PathBuf>,
) -> Option<String> {
resolve_token(
|var| env(var).and_then(|v| v.into_string().ok()),
|| {
read_token_file(
&token_path_from(&env, home.clone()),
legacy_token_path_from(&env, home).as_deref(),
)
},
)
}
fn resolve_token(
env: impl Fn(&str) -> Option<String>,
file: impl FnOnce() -> Option<String>,
) -> Option<String> {
for var in ["HF_TOKEN", "HUGGING_FACE_HUB_TOKEN"] {
if let Some(t) = env(var) {
let t = t.trim().to_string();
if !t.is_empty() {
return Some(t);
}
}
}
file()
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
}
#[derive(Deserialize)]
struct WhoAmI {
name: Option<String>,
}
pub fn whoami(token: &str) -> Result<String> {
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(30))
.build()
.context("build http client")?;
let resp = client
.get(format!("{}/api/whoami-v2", endpoint()))
.header("authorization", format!("Bearer {token}"))
.send()
.context("request whoami-v2")?;
let status = resp.status();
if status == reqwest::StatusCode::UNAUTHORIZED {
anyhow::bail!("invalid user token");
}
if !status.is_success() {
let body = resp.text().unwrap_or_default();
anyhow::bail!("whoami-v2 returned {status}: {body}");
}
let info: WhoAmI = resp.json().context("parse whoami-v2 response")?;
info.name
.ok_or_else(|| anyhow!("whoami-v2 response missing \"name\""))
}
pub fn login(token: &str) -> Result<String> {
let username = whoami(token)?;
let path = token_path();
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let _ = std::fs::set_permissions(parent, std::fs::Permissions::from_mode(0o700));
}
}
#[cfg(unix)]
{
use std::io::Write as _;
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.mode(0o600)
.open(&path)
.and_then(|mut f| {
f.set_permissions(std::fs::Permissions::from_mode(0o600))?;
f.write_all(token.trim().as_bytes())
})
.with_context(|| format!("write {}", path.display()))?;
}
#[cfg(not(unix))]
std::fs::write(&path, token.trim()).with_context(|| format!("write {}", path.display()))?;
Ok(username)
}
pub fn logout() -> Result<()> {
for path in std::iter::once(token_path()).chain(legacy_token_path()) {
match std::fs::remove_file(&path) {
Ok(()) => {}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => return Err(e).context(format!("remove {}", path.display())),
}
}
Ok(())
}
fn is_known_oci_host(host: &str) -> bool {
matches!(
host,
"ghcr.io"
| "docker.io"
| "index.docker.io"
| "registry-1.docker.io"
| "quay.io"
| "gcr.io"
| "mcr.microsoft.com"
| "public.ecr.aws"
)
}
pub(crate) fn is_known_hf_host(host: &str) -> bool {
matches!(host, "hf.co" | "huggingface.co" | "modelscope.cn")
}
async fn is_oci_registry(host: &str) -> bool {
let Ok(client) = reqwest::Client::builder()
.timeout(Duration::from_secs(5))
.build()
else {
return false;
};
for scheme in ["https", "http"] {
let Ok(resp) = client
.get(format!("{scheme}://{host}/v2/"))
.timeout(Duration::from_secs(3))
.send()
.await
else {
continue;
};
let headers = resp.headers();
if headers.contains_key("docker-distribution-api-version") {
return true;
}
if resp.status() == reqwest::StatusCode::UNAUTHORIZED
&& headers.contains_key("www-authenticate")
{
return true;
}
}
false
}
pub async fn is_oci_host(host: &str) -> bool {
if is_known_hf_host(host) {
return false;
}
if is_known_oci_host(host) || crate::config::has_registry_mirrors(host) {
return true;
}
is_oci_registry(host).await
}
pub enum ClassifiedRef {
Hf(String),
Source(String),
Other(String),
}
pub async fn classify(reference: &str) -> ClassifiedRef {
for prefix in ["hf://", "huggingface://"] {
if let Some(rest) = reference.strip_prefix(prefix) {
let host_less = rest.split('/').filter(|s| !s.is_empty()).count() == 2;
return ClassifiedRef::Hf(if host_less {
format!("huggingface.co/{rest}")
} else {
rest.to_string()
});
}
}
if crate::sources::handles(reference) {
return ClassifiedRef::Source(reference.to_string());
}
if reference.contains("://") || reference.starts_with('/') {
return ClassifiedRef::Other(reference.to_string());
}
let normalized = if reference.rfind(':').unwrap_or(0) <= reference.rfind('/').unwrap_or(0) {
format!("{reference}:latest")
} else {
reference.to_string()
};
let host = normalized.split('/').next().unwrap_or(&normalized);
if !is_oci_host(host).await {
ClassifiedRef::Hf(normalized)
} else {
ClassifiedRef::Other(normalized)
}
}
pub fn hf_endpoint(host: &str) -> String {
hf_endpoint_from(|var| std::env::var_os(var), host)
}
fn hf_endpoint_from(env: impl Fn(&str) -> Option<std::ffi::OsString>, host: &str) -> String {
match endpoint_override(env, &["MODEL_ENDPOINT", "HF_ENDPOINT"]) {
Some(base) => format!("{base}/"),
None if host == "hf.co" => "https://huggingface.co/".to_string(),
None => format!("https://{host}/"),
}
}
pub(crate) fn api_client() -> Result<reqwest::Client> {
reqwest::Client::builder()
.timeout(Duration::from_secs(120))
.build()
.context("build HF API client")
}
pub(crate) fn download_client() -> Result<reqwest::Client> {
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(30))
.tcp_keepalive(Duration::from_secs(30))
.read_timeout(Duration::from_secs(60))
.build()
.context("build HF download client")
}
pub(crate) fn head_client() -> Result<reqwest::Client> {
reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.build()
.context("build no-redirect HTTP client")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn is_hf_host_matches_known_hosts_case_insensitively() {
assert!(is_hf_host("hf.co"));
assert!(is_hf_host("HuggingFace.co"));
assert!(is_hf_host("https://huggingface.co"));
assert!(is_hf_host("www.huggingface.co"));
assert!(!is_hf_host("registry.example.com"));
assert!(!is_hf_host("docker.io"));
assert!(!is_hf_host("modelscope.cn"));
}
#[test]
fn parse_max_transfer_streams_defaults_to_four_on_unset_or_unparseable() {
assert_eq!(parse_max_transfer_streams(None), 4);
assert_eq!(parse_max_transfer_streams(Some("")), 4);
assert_eq!(parse_max_transfer_streams(Some("garbage")), 4);
assert_eq!(parse_max_transfer_streams(Some("8")), 8);
assert_eq!(parse_max_transfer_streams(Some(" 2 ")), 2);
}
#[test]
fn parse_max_transfer_streams_clamps_an_explicit_zero_to_one() {
assert_eq!(parse_max_transfer_streams(Some("0")), 1);
}
#[test]
fn hf_home_follows_huggingface_hub_defaults() {
let home = || Some(PathBuf::from("/home/u"));
let env = |pairs: &'static [(&'static str, &'static str)]| {
move |var: &str| {
pairs
.iter()
.find(|(k, _)| *k == var)
.map(|(_, v)| std::ffi::OsString::from(v))
}
};
let cases: &[(&'static [(&'static str, &'static str)], &str)] = &[
(&[], "/home/u/.cache/huggingface"),
(&[("XDG_CACHE_HOME", "/x")], "/x/huggingface"),
(&[("HF_HOME", "/h"), ("XDG_CACHE_HOME", "/x")], "/h"),
(
&[("HF_HOME", ""), ("XDG_CACHE_HOME", "/x")],
"/x/huggingface",
),
(&[("XDG_CACHE_HOME", "")], "/home/u/.cache/huggingface"),
];
for (pairs, expected) in cases {
assert_eq!(
hf_home_from(env(pairs), home()),
PathBuf::from(expected),
"env {pairs:?}"
);
}
}
#[test]
fn legacy_token_path_only_when_xdg_cache_home_moved_the_default() {
let home = || Some(PathBuf::from("/home/u"));
let env = |pairs: &'static [(&'static str, &'static str)]| {
move |var: &str| {
pairs
.iter()
.find(|(k, _)| *k == var)
.map(|(_, v)| std::ffi::OsString::from(v))
}
};
type Env = &'static [(&'static str, &'static str)];
let legacy = Some("/home/u/.cache/huggingface/token");
let cases: &[(Env, Option<&str>)] = &[
(&[], None),
(&[("XDG_CACHE_HOME", "/x")], legacy),
(&[("XDG_CACHE_HOME", "/home/u/.cache")], None),
(&[("XDG_CACHE_HOME", "")], None),
(&[("HF_HOME", "/h"), ("XDG_CACHE_HOME", "/x")], None),
(&[("HF_TOKEN_PATH", "/t"), ("XDG_CACHE_HOME", "/x")], None),
(&[("HF_HOME", ""), ("XDG_CACHE_HOME", "/x")], legacy),
];
for (pairs, expected) in cases {
assert_eq!(
legacy_token_path_from(env(pairs), home()),
expected.map(PathBuf::from),
"env {pairs:?}"
);
}
}
#[test]
fn read_token_file_falls_back_only_when_the_file_is_missing() {
let dir = tempfile::tempdir().unwrap();
let current = dir.path().join("current");
let legacy = dir.path().join("legacy");
std::fs::write(&legacy, "hf_old").unwrap();
assert_eq!(
read_token_file(¤t, Some(&legacy)).as_deref(),
Some("hf_old")
);
assert_eq!(read_token_file(¤t, None), None);
std::fs::write(¤t, "hf_new").unwrap();
assert_eq!(
read_token_file(¤t, Some(&legacy)).as_deref(),
Some("hf_new")
);
std::fs::write(¤t, "").unwrap();
assert_eq!(
read_token_file(¤t, Some(&legacy)).as_deref(),
Some("")
);
}
#[test]
fn read_token_file_does_not_fall_back_when_the_path_cannot_be_read() {
let dir = tempfile::tempdir().unwrap();
let current = dir.path().join("current");
let legacy = dir.path().join("legacy");
std::fs::create_dir(¤t).unwrap();
std::fs::write(&legacy, "hf_old").unwrap();
assert_eq!(read_token_file(¤t, Some(&legacy)), None);
}
#[test]
fn token_resolves_env_then_token_file_then_legacy_file() {
let home = tempfile::tempdir().unwrap();
let xdg = home.path().join("xdg");
let legacy = home.path().join(".cache/huggingface/token");
let current = xdg.join("huggingface/token");
let env = |pairs: Vec<(&'static str, std::ffi::OsString)>| {
move |var: &str| {
pairs
.iter()
.find(|(k, _)| *k == var)
.map(|(_, v)| v.clone())
}
};
let token = |pairs: Vec<(&'static str, std::ffi::OsString)>| {
token_from(env(pairs), Some(home.path().to_path_buf()))
};
let xdg_only = || vec![("XDG_CACHE_HOME", xdg.clone().into_os_string())];
assert_eq!(token(xdg_only()), None);
std::fs::create_dir_all(legacy.parent().unwrap()).unwrap();
std::fs::write(&legacy, "hf_old\n").unwrap();
assert_eq!(token(xdg_only()).as_deref(), Some("hf_old"));
let hf_home = home.path().join("hf");
assert_eq!(
token(vec![
("HF_HOME", hf_home.into_os_string()),
("XDG_CACHE_HOME", xdg.clone().into_os_string()),
]),
None
);
std::fs::create_dir_all(current.parent().unwrap()).unwrap();
std::fs::write(¤t, "hf_new").unwrap();
assert_eq!(token(xdg_only()).as_deref(), Some("hf_new"));
let elsewhere = home.path().join("elsewhere");
std::fs::write(&elsewhere, "hf_path").unwrap();
assert_eq!(
token(vec![("HF_TOKEN_PATH", elsewhere.clone().into_os_string())]).as_deref(),
Some("hf_path")
);
let both = home.path().join("both");
std::fs::create_dir_all(&both).unwrap();
std::fs::write(both.join("token"), "hf_home").unwrap();
assert_eq!(
token(vec![
("HF_TOKEN_PATH", elsewhere.into_os_string()),
("HF_HOME", both.into_os_string()),
])
.as_deref(),
Some("hf_path")
);
let mut pairs = xdg_only();
pairs.push(("HF_TOKEN", " hf_env ".into()));
assert_eq!(token(pairs).as_deref(), Some("hf_env"));
}
#[cfg(unix)]
#[test]
fn token_from_treats_a_non_unicode_env_var_as_unset() {
use std::os::unix::ffi::OsStringExt;
let home = tempfile::tempdir().unwrap();
let invalid = std::ffi::OsString::from_vec(vec![0xff]);
let token = token_from(
|var| match var {
"HF_TOKEN" => Some(invalid.clone()),
"HUGGING_FACE_HUB_TOKEN" => Some("hf_legacy".into()),
_ => None,
},
Some(home.path().to_path_buf()),
);
assert_eq!(token.as_deref(), Some("hf_legacy"));
}
#[test]
fn resolve_token_prefers_hf_token_then_legacy_var_then_file() {
fn env<'a>(pairs: &'a [(&'a str, &'a str)]) -> impl Fn(&str) -> Option<String> + 'a {
move |var| {
pairs
.iter()
.find(|(k, _)| *k == var)
.map(|(_, v)| v.to_string())
}
}
fn file(s: Option<&str>) -> impl FnOnce() -> Option<String> + '_ {
move || s.map(str::to_string)
}
type Case<'a> = (&'a [(&'a str, &'a str)], Option<&'a str>, Option<&'a str>);
let cases: &[Case] = &[
(&[], None, None),
(&[], Some("hf_file\n"), Some("hf_file")),
(&[], Some(" \n"), None),
(&[("HF_TOKEN", " hf_env ")], Some("hf_file"), Some("hf_env")),
(
&[
("HF_TOKEN", "hf_env"),
("HUGGING_FACE_HUB_TOKEN", "hf_legacy"),
],
None,
Some("hf_env"),
),
(
&[("HUGGING_FACE_HUB_TOKEN", "hf_legacy")],
Some("hf_file"),
Some("hf_legacy"),
),
(
&[("HF_TOKEN", ""), ("HUGGING_FACE_HUB_TOKEN", "hf_legacy")],
None,
Some("hf_legacy"),
),
(&[("HF_TOKEN", " ")], Some("hf_file"), Some("hf_file")),
];
for (pairs, on_disk, expected) in cases {
assert_eq!(
resolve_token(env(pairs), file(*on_disk)).as_deref(),
*expected,
"env {pairs:?}, file {on_disk:?}"
);
}
}
#[test]
fn resolve_token_reads_the_file_only_when_no_env_var_is_set() {
let read = std::cell::Cell::new(false);
let token = resolve_token(
|var| (var == "HF_TOKEN").then(|| "hf_env".to_string()),
|| {
read.set(true);
Some("hf_file".to_string())
},
);
assert_eq!(token.as_deref(), Some("hf_env"));
assert!(
!read.get(),
"the token file was read although HF_TOKEN was set"
);
}
#[test]
fn is_known_hf_host_includes_modelscope() {
assert!(is_known_hf_host("modelscope.cn"));
assert!(is_known_hf_host("huggingface.co"));
assert!(!is_known_hf_host("docker.io"));
}
#[test]
fn is_known_oci_host_matches_the_usual_registries() {
assert!(is_known_oci_host("docker.io"));
assert!(is_known_oci_host("ghcr.io"));
assert!(!is_known_oci_host("huggingface.co"));
}
#[tokio::test]
async fn classify_strips_hf_scheme_prefixes_and_defaults_the_host() {
match classify("hf://owner/repo:tag").await {
ClassifiedRef::Hf(r) => assert_eq!(r, "huggingface.co/owner/repo:tag"),
_ => panic!("expected Hf"),
}
match classify("huggingface://owner/repo").await {
ClassifiedRef::Hf(r) => assert_eq!(r, "huggingface.co/owner/repo"),
_ => panic!("expected Hf"),
}
}
#[tokio::test]
async fn classify_leaves_an_explicit_host_after_the_hf_scheme_alone() {
match classify("hf://modelscope.cn/owner/repo").await {
ClassifiedRef::Hf(r) => assert_eq!(r, "modelscope.cn/owner/repo"),
_ => panic!("expected Hf"),
}
}
#[tokio::test]
async fn classify_routes_every_uri_scheme_source_and_local_path_to_sources() {
for r in [
"ms://owner/repo",
"modelscope://owner/repo",
"ngc://org/team/model",
"s3://bucket/key",
"gs://bucket/key",
"/abs/path",
] {
match classify(r).await {
ClassifiedRef::Source(got) => assert_eq!(got, r),
_ => panic!("expected Source for {r}"),
}
}
}
#[tokio::test]
async fn classify_leaves_an_unknown_scheme_alone() {
match classify("wat://owner/repo").await {
ClassifiedRef::Other(got) => assert_eq!(got, "wat://owner/repo"),
_ => panic!("expected Other"),
}
}
#[tokio::test]
async fn classify_treats_a_known_registry_host_as_other() {
match classify("docker.io/library/alpine").await {
ClassifiedRef::Other(got) => assert_eq!(got, "docker.io/library/alpine:latest"),
_ => panic!("expected Other"),
}
}
#[tokio::test]
async fn classify_treats_a_bare_hf_host_as_hf() {
match classify("huggingface.co/owner/repo").await {
ClassifiedRef::Hf(got) => assert_eq!(got, "huggingface.co/owner/repo:latest"),
_ => panic!("expected Hf"),
}
}
#[test]
fn endpoint_defaults_to_huggingface_and_drops_trailing_slashes() {
let env = |value: Option<&'static str>| {
move |var: &str| match var {
"HF_ENDPOINT" => value.map(std::ffi::OsString::from),
_ => None,
}
};
assert_eq!(endpoint_from(env(None)), "https://huggingface.co");
assert_eq!(endpoint_from(env(Some(""))), "https://huggingface.co");
assert_eq!(
endpoint_from(env(Some("https://hf-mirror.example/"))),
"https://hf-mirror.example"
);
assert_eq!(
endpoint_from(env(Some("https://hf-mirror.example//"))),
"https://hf-mirror.example"
);
}
#[cfg(unix)]
#[test]
fn endpoint_from_treats_a_non_unicode_env_var_as_unset() {
use std::os::unix::ffi::OsStringExt;
let invalid = std::ffi::OsString::from_vec(vec![0xff]);
let endpoint = endpoint_from(|var| (var == "HF_ENDPOINT").then(|| invalid.clone()));
assert_eq!(endpoint, "https://huggingface.co");
}
#[test]
fn hf_endpoint_defaults_hf_co_to_the_canonical_huggingface_domain() {
assert_eq!(
hf_endpoint_from(|_| None, "hf.co"),
"https://huggingface.co/"
);
}
#[test]
fn hf_endpoint_uses_the_host_verbatim_otherwise() {
assert_eq!(
hf_endpoint_from(|_| None, "modelscope.cn"),
"https://modelscope.cn/"
);
}
#[test]
fn hf_endpoint_prefers_model_endpoint_then_hf_endpoint_with_one_trailing_slash() {
let env = |model: Option<&'static str>, hf: Option<&'static str>| {
move |var: &str| match var {
"MODEL_ENDPOINT" => model.map(std::ffi::OsString::from),
"HF_ENDPOINT" => hf.map(std::ffi::OsString::from),
_ => None,
}
};
assert_eq!(
hf_endpoint_from(
env(Some("https://model.example//"), Some("https://hf.example")),
"hf.co"
),
"https://model.example/"
);
assert_eq!(
hf_endpoint_from(env(Some(""), Some("https://hf.example")), "modelscope.cn"),
"https://hf.example/"
);
assert_eq!(
hf_endpoint_from(env(None, Some("https://hf.example/")), "modelscope.cn"),
"https://hf.example/"
);
assert_eq!(
hf_endpoint_from(env(Some(""), Some("")), "hf.co"),
"https://huggingface.co/"
);
}
#[cfg(unix)]
#[test]
fn hf_endpoint_from_skips_a_non_unicode_model_endpoint() {
use std::os::unix::ffi::OsStringExt;
let invalid = std::ffi::OsString::from_vec(vec![0xff]);
let endpoint = hf_endpoint_from(
|var| match var {
"MODEL_ENDPOINT" => Some(invalid.clone()),
"HF_ENDPOINT" => Some("https://hf.example".into()),
_ => None,
},
"hf.co",
);
assert_eq!(endpoint, "https://hf.example/");
}
}