| 197 | } |
| 198 | |
| 199 | static nl::json api_get(const std::string & url, |
| 200 | const std::string & token) { |
| 201 | auto [cli, parts] = common_http_client(url); |
| 202 | |
| 203 | httplib::Headers headers = { |
| 204 | {"User-Agent", "llama-cpp/" + std::string(llama_build_info())}, |
| 205 | {"Accept", "application/json"} |
| 206 | }; |
| 207 | |
| 208 | if (is_valid_hf_token(token)) { |
| 209 | headers.emplace("Authorization", "Bearer " + token); |
| 210 | } else if (!token.empty()) { |
| 211 | LOG_WRN("%s: invalid token, authentication disabled\n", __func__); |
| 212 | } |
| 213 | |
| 214 | if (auto res = cli.Get(parts.path, headers)) { |
| 215 | auto body = res->body; |
| 216 | |
| 217 | if (res->status == 200) { |
| 218 | return nl::json::parse(res->body); |
| 219 | } |
| 220 | try { |
| 221 | body = nl::json::parse(res->body)["error"].get<std::string>(); |
| 222 | } catch (...) { } |
| 223 | |
| 224 | throw std::runtime_error("GET failed (" + std::to_string(res->status) + "): " + body); |
| 225 | } else { |
| 226 | throw std::runtime_error("HTTPLIB failed: " + httplib::to_string(res.error())); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static std::string get_repo_commit(const std::string & repo_id, |
| 231 | const std::string & token) { |
no test coverage detected