HuggingFace file auto-detection and HTTP download
| 411 | |
| 412 | // HuggingFace file auto-detection and HTTP download |
| 413 | static std::pair<long, std::vector<char>> gguf_http_get( |
| 414 | const std::string & url, |
| 415 | const httplib::Headers & headers = {}, |
| 416 | int timeout_sec = 60) { |
| 417 | try { |
| 418 | auto [cli, parts] = common_http_client(url); |
| 419 | |
| 420 | if (timeout_sec > 0) { |
| 421 | cli.set_read_timeout(timeout_sec, 0); |
| 422 | cli.set_write_timeout(timeout_sec, 0); |
| 423 | } |
| 424 | cli.set_connection_timeout(30, 0); |
| 425 | |
| 426 | std::vector<char> body; |
| 427 | auto res = cli.Get(parts.path, headers, |
| 428 | [&](const char * data, size_t len) { |
| 429 | body.insert(body.end(), data, data + len); |
| 430 | return true; |
| 431 | }, nullptr); |
| 432 | |
| 433 | if (!res) { |
| 434 | fprintf(stderr, "gguf_fetch: HTTP request failed for %s (error %d)\n", |
| 435 | url.c_str(), (int)res.error()); |
| 436 | return {-1, {}}; |
| 437 | } |
| 438 | return {res->status, std::move(body)}; |
| 439 | } catch (const std::exception & e) { |
| 440 | fprintf(stderr, "gguf_fetch: HTTP error: %s\n", e.what()); |
| 441 | return {-1, {}}; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | // Find the filename for given repo/quant. |
| 446 | // For split models, returns the first shard (the one containing "00001-of-") |
no test coverage detected