Add Hugging Face support and enhance model resolution logic
- Introduced support for Hugging Face API integration, allowing fallback model resolution when Civitai fails. - Updated configuration to include `HF_TOKEN` and `HF_TOKEN_PATH` for authentication. - Enhanced model capture logic to differentiate between Civitai and Hugging Face sources. - Improved error handling for model downloads, providing clearer messages for authentication issues. - Updated documentation to reflect new environment variables and usage instructions for Hugging Face integration. - Added tests to validate the new fallback mechanism and ensure robust model resolution.
This commit is contained in:
@@ -236,6 +236,7 @@ def run_doctor() -> list[Check]:
|
||||
)
|
||||
|
||||
_civitai(cfg, checks)
|
||||
_huggingface(cfg, checks)
|
||||
_local_manifests(cfg, checks)
|
||||
_local_folders(cfg, checks)
|
||||
return checks
|
||||
@@ -279,6 +280,58 @@ def _civitai(cfg: Config, checks: list[Check]) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _huggingface(cfg: Config, checks: list[Check]) -> None:
|
||||
from gpu_rent.huggingface import is_huggingface_url, probe_whoami
|
||||
from gpu_rent.llm_runtime import normalize_runtime, parse_llamacpp_models
|
||||
from gpu_rent.manifests import parse_models
|
||||
|
||||
needs_hf = False
|
||||
try:
|
||||
for e in parse_models(cfg.models_manifest):
|
||||
if e.url and is_huggingface_url(e.url):
|
||||
needs_hf = True
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if normalize_runtime(cfg.llm_runtime) == "llamacpp":
|
||||
for e in parse_llamacpp_models(cfg.llamacpp_models_manifest):
|
||||
if e.url and is_huggingface_url(e.url):
|
||||
needs_hf = True
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not cfg.hf_token:
|
||||
checks.append(
|
||||
Check(
|
||||
"Hugging Face",
|
||||
True,
|
||||
False,
|
||||
(
|
||||
"HF_TOKEN нет — gated GGUF / HF в models.yaml дадут 401. "
|
||||
"https://huggingface.co/settings/tokens"
|
||||
if needs_hf
|
||||
else "токена нет (опционально для HF URL / capture fallback)"
|
||||
),
|
||||
)
|
||||
)
|
||||
return
|
||||
probe = probe_whoami(cfg.hf_token)
|
||||
if probe.ok:
|
||||
who = f" ({probe.name})" if probe.name else ""
|
||||
checks.append(Check("Hugging Face", True, True, f"токен ок{who}"))
|
||||
else:
|
||||
checks.append(
|
||||
Check(
|
||||
"Hugging Face",
|
||||
True,
|
||||
False,
|
||||
f"токен не принят: {probe.detail}",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _local_manifests(cfg: Config, checks: list[Check]) -> None:
|
||||
try:
|
||||
models = parse_models(cfg.models_manifest)
|
||||
|
||||
Reference in New Issue
Block a user