Last updated: 2026-07-21
Managed Models
Hf
Resolve and download Hugging Face GGUF models for the `-hf` CLI flag.
Turns an `owner/repo[:quant]` spec into an installed GGUF in the managed model cache, resolving the concrete file name via the Hugging Face `/v2/<repo>/manifests/<tag>` endpoint and reusing the managed download pipeline for transfer, staging, and manifest bookkeeping.
4 exports shown
struct
Spec
pub const Spec = struct Parsed `-hf` argument: a Hugging Face repo plus a quantization tag.
function
parseSpec
pub fn parseSpec(text: []const u8) !Spec Parses an `-hf` argument of the form `owner/repo[:quant]`.
The quantization suffix is optional; when absent the tag defaults to `latest`, which the Hugging Face manifest endpoint resolves to the repo's recommended quantization. Each component (owner, repo, tag) must match the Hugging Face naming grammar; anything else fails with `error.InvalidHfSpec`.
function
cacheId
pub fn cacheId(allocator: std.mem.Allocator, spec: Spec) ![]u8 Derives the managed-cache model id for a Hugging Face spec.
The id is a single filesystem-safe path component so the download can live in the same `<cache_root>/models/<id>/model.gguf` layout as catalog models. Distinct specs map to distinct ids; `:latest` is cached separately from an explicit quantization even if both resolve to the same upstream file.
function
ensureModel
pub fn ensureModel(spec_text: []const u8, allocator: std.mem.Allocator, writer: anytype) ![]u8 Ensures the model described by an `-hf` spec is installed and returns its path.
If the spec is already cached the installed path is returned without any network access. Otherwise the GGUF file name and sha256 digest are resolved via the Hugging Face manifest endpoint and the file is downloaded through the managed pull pipeline (staged `.partial` file, progress bar, manifest write), which verifies the download against the pinned digest when the manifest provides one. quantizations with no kernels (`error.UnsupportedQuantization`, detected from the tag and the resolved file name) and architectures the loader does not recognise (`error.UnsupportedArchitecture`, detected from repo metadata when available).