| 36 | namespace fs = std::filesystem; |
| 37 | |
| 38 | static fs::path get_cache_directory() { |
| 39 | static const fs::path cache = []() { |
| 40 | struct { |
| 41 | const char * var; |
| 42 | fs::path path; |
| 43 | } entries[] = { |
| 44 | {"LLAMA_CACHE", fs::path()}, |
| 45 | {"HF_HUB_CACHE", fs::path()}, |
| 46 | {"HUGGINGFACE_HUB_CACHE", fs::path()}, |
| 47 | {"HF_HOME", fs::path("hub")}, |
| 48 | {"XDG_CACHE_HOME", fs::path("huggingface") / "hub"}, |
| 49 | {HOME_DIR, fs::path(".cache") / "huggingface" / "hub"} |
| 50 | }; |
| 51 | for (const auto & entry : entries) { |
| 52 | if (auto * p = std::getenv(entry.var); p && *p) { |
| 53 | fs::path base(p); |
| 54 | return entry.path.empty() ? base : base / entry.path; |
| 55 | } |
| 56 | } |
| 57 | #ifndef _WIN32 |
| 58 | const struct passwd * pw = getpwuid(getuid()); |
| 59 | |
| 60 | if (pw->pw_dir && *pw->pw_dir) { |
| 61 | return fs::path(pw->pw_dir) / ".cache" / "huggingface" / "hub"; |
| 62 | } |
| 63 | #endif |
| 64 | throw std::runtime_error("Failed to determine HF cache directory"); |
| 65 | }(); |
| 66 | |
| 67 | return cache; |
| 68 | } |
| 69 | |
| 70 | static std::string folder_name_to_repo(const std::string & folder) { |
| 71 | constexpr std::string_view prefix = "models--"; |
no test coverage detected