NOTE: this is copied from common.cpp to avoid linking with libcommon
| 124 | |
| 125 | // NOTE: this is copied from common.cpp to avoid linking with libcommon |
| 126 | static std::string fs_get_cache_directory() { |
| 127 | std::string cache_directory = ""; |
| 128 | auto ensure_trailing_slash = [](std::string p) { |
| 129 | // Make sure to add trailing slash |
| 130 | if (p.back() != DIRECTORY_SEPARATOR) { |
| 131 | p += DIRECTORY_SEPARATOR; |
| 132 | } |
| 133 | return p; |
| 134 | }; |
| 135 | if (getenv("LLAMA_CACHE")) { |
| 136 | cache_directory = std::getenv("LLAMA_CACHE"); |
| 137 | } else { |
| 138 | #if defined(__linux__) || defined(__FreeBSD__) || defined(_AIX) || \ |
| 139 | defined(__OpenBSD__) || defined(__NetBSD__) |
| 140 | if (std::getenv("XDG_CACHE_HOME")) { |
| 141 | cache_directory = std::getenv("XDG_CACHE_HOME"); |
| 142 | } else if (std::getenv("HOME")) { |
| 143 | cache_directory = std::getenv("HOME") + std::string("/.cache/"); |
| 144 | } else { |
| 145 | #if defined(__linux__) |
| 146 | /* no $HOME is defined, fallback to getpwuid */ |
| 147 | struct passwd *pw = getpwuid(getuid()); |
| 148 | if ((!pw) || (!pw->pw_dir)) { |
| 149 | throw std::runtime_error("Failed to find $HOME directory"); |
| 150 | } |
| 151 | |
| 152 | cache_directory = std::string(pw->pw_dir) + std::string("/.cache/"); |
| 153 | #else /* defined(__linux__) */ |
| 154 | throw std::runtime_error("Failed to find $HOME directory"); |
| 155 | #endif /* defined(__linux__) */ |
| 156 | } |
| 157 | #elif defined(__APPLE__) |
| 158 | cache_directory = std::getenv("HOME") + std::string("/Library/Caches/"); |
| 159 | #elif defined(_WIN32) |
| 160 | cache_directory = std::getenv("LOCALAPPDATA"); |
| 161 | #elif defined(__EMSCRIPTEN__) |
| 162 | GGML_ABORT("not implemented on this platform"); |
| 163 | #else |
| 164 | # error Unknown architecture |
| 165 | #endif |
| 166 | cache_directory = ensure_trailing_slash(cache_directory); |
| 167 | cache_directory += "llama.cpp"; |
| 168 | } |
| 169 | return ensure_trailing_slash(cache_directory); |
| 170 | } |
| 171 | |
| 172 | struct rpc_server_params { |
| 173 | std::string host = "127.0.0.1"; |
no test coverage detected