use dirs::home_dir;
pub fn get_token() -> anyhow::Result<String> {
if let Ok(token) = std::env::var("HF_TOKEN") {
return Ok(token);
};
if let Some(home) = home_dir() {
let file = home.join(".cache/huggingface/token");
if file.exists() {
if let Ok(content) = std::fs::read_to_string(file) {
if !content.is_empty() {
return Ok(content);
}
}
}
};
anyhow::bail!(
"Hugging Face authentication token not found. Please set the HF_TOKEN environment variable or run 'huggingface-cli login' to authenticate."
)
}