fetchFromHuggingFace
pkgs.fetchFromHuggingFace
Functor
Docs pulled from | This Revision | 19 minutes ago
Contribute
Enhance the ecosystem with your expertise! Contribute to fill the gaps in documentation. Your input can make a difference.
Noogle detected
This is a Functor
Learn about functors
Implementation
The following is the current implementation of this function.
{
repoId,
tag ? null,
rev ? null,
name ? repoRevToNameMaybe repoId (lib.revOrTag rev tag) "huggingface",
domain ? "huggingface.co",
repoType ? "model",
backend ? "xet",
branchName ? null,
deepClone ? false,
fetchSubmodules ? false,
fetchTags ? false,
leaveDotGit ? null,
rootDir ? "",
sparseCheckout ? null,
passthru ? { },
meta ? { },
... # For hash agility and additional fetchgit arguments
}@args:
assert (
lib.assertMsg (lib.xor (tag == null) (
rev == null
)) "fetchFromHuggingFace requires one of either `rev` or `tag` to be provided (not both)."
);
assert (lib.assertOneOf "repoType" repoType (builtins.attrNames repoPrefixes));
assert (
lib.assertOneOf "backend" backend [
"lfs"
"xet"
]
);
let
position = (
if args.meta.description or null != null then
builtins.unsafeGetAttrPos "description" args.meta
else if tag != null then
builtins.unsafeGetAttrPos "tag" args
else
builtins.unsafeGetAttrPos "rev" args
);
baseUrl = "https://${domain}/${repoPrefixes.${repoType}}${repoId}";
gitRepoUrl = "${baseUrl}.git";
newMeta =
meta
// {
homepage = meta.homepage or baseUrl;
}
// lib.optionalAttrs (position != null) {
# to indicate where derivation originates, similar to make-derivation.nix's mkDerivation
position = "${position.file}:${toString position.line}";
};
backendFetcher = builtins.getAttr backend {
lfs = fetchgit;
xet = throw "fetchFromHuggingFace: the Xet backend is not implemented yet";
};
in
assert (
lib.assertMsg (
builtins.match "[^/]+(/[^/]+)?" repoId != null
) "fetchFromHuggingFace requires `repoId` to be in the form `repo` or `owner/repo`."
);
backendFetcher (
removeAttrs args [
"backend"
"domain"
"repoId"
"repoType"
]
// {
inherit
branchName
deepClone
fetchSubmodules
fetchTags
leaveDotGit
name
rootDir
sparseCheckout
tag
rev
;
url = gitRepoUrl;
fetchLFS = true;
meta = newMeta;
passthru = {
inherit gitRepoUrl;
}
// passthru;
}
)
// {
inherit
repoId
repoType
;
}