Implementation:Ggml org Llama cpp Download Header
| Knowledge Sources | |
|---|---|
| Domains | Networking, Model_Management |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Declares the API for downloading models from HuggingFace Hub, Docker registries, and direct URLs with caching support.
Description
This header defines `common_remote_params` for HTTP configuration (headers, timeout, max_size) and `common_remote_get_content` for raw URL fetching. It provides `common_download_split_repo_tag` to parse "user/model:tag" strings, `common_get_hf_file` to resolve HF repo tags to specific GGUF files (with optional mmproj files), and `common_download_model` for the full download workflow. Additionally, `common_list_cached_models` returns locally cached models, `common_download_file_single` downloads individual files, and `common_docker_resolve_model` resolves models from Docker/OCI registries.
Usage
Use this header when implementing model acquisition features such as `--hf-repo` and `--model-url` CLI options. Include it to download models from HuggingFace, resolve Docker registry references, or manage the local model cache.
Code Reference
Source Location
- Repository: Ggml_org_Llama_cpp
- File: common/download.h
- Lines: 1-84
Signature
struct common_remote_params {
common_header_list headers;
long timeout = 0;
long max_size = 0;
};
std::pair<long, std::vector<char>> common_remote_get_content(const std::string & url, const common_remote_params & params);
std::pair<std::string, std::string> common_download_split_repo_tag(const std::string & hf_repo_with_tag);
common_hf_file_res common_get_hf_file(
const std::string & hf_repo_with_tag,
const std::string & bearer_token,
bool offline,
const common_header_list & headers = {});
bool common_download_model(
const common_params_model & model,
const std::string & bearer_token,
bool offline,
const common_header_list & headers = {});
std::vector<common_cached_model_info> common_list_cached_models();
int common_download_file_single(const std::string & url,
const std::string & path,
const std::string & bearer_token,
bool offline,
const common_header_list & headers = {});
std::string common_docker_resolve_model(const std::string & docker);
Import
#include "download.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| url | const std::string & | Yes | URL to fetch content from or download a file from |
| params | const common_remote_params & | Yes | HTTP configuration including headers, timeout, and max size |
| hf_repo_with_tag | const std::string & | Yes | HuggingFace repo string in "user/model:tag" format |
| bearer_token | const std::string & | Yes | Authentication token for HuggingFace API |
| offline | bool | Yes | If true, only use cached data without network requests |
| headers | const common_header_list & | No | Additional HTTP headers for requests |
| model | const common_params_model & | Yes | Model parameters for download_model |
| path | const std::string & | Yes | Local file path for single file download |
| docker | const std::string & | Yes | Docker registry reference string |
Outputs
| Name | Type | Description |
|---|---|---|
| remote_get_content return | std::pair<long, std::vector<char>> | HTTP status code and raw response body |
| split_repo_tag return | std::pair<std::string, std::string> | Separated repo name and tag |
| get_hf_file return | common_hf_file_res | Resolved repo, GGUF file path, and optional mmproj file path |
| download_model return | bool | True if download succeeded |
| list_cached_models return | std::vector<common_cached_model_info> | List of locally cached model information |
| download_file_single return | int | HTTP status code or -1 on error |
| docker_resolve_model return | std::string | Local path to the downloaded model file |
Usage Examples
#include "download.h"
// Parse a HuggingFace repo with tag
auto [repo, tag] = common_download_split_repo_tag("bartowski/Llama-3.2-3B-Instruct-GGUF:Q4_K_M");
// repo = "bartowski/Llama-3.2-3B-Instruct-GGUF", tag = "Q4_K_M"
// Resolve HF repo to specific GGUF file
auto hf_file = common_get_hf_file("bartowski/Llama-3.2-3B-Instruct-GGUF:Q4_K_M", token, false);
// Download a model
common_params_model model_params;
bool success = common_download_model(model_params, token, false);
// List cached models
auto cached = common_list_cached_models();