Skip to content

Commit fd7b2df

Browse files
committed
feat(downloader): add HF_MIRROR environment variable support
- Added HF_MIRROR env var to configure HuggingFace mirror URLs - HF_MIRROR takes precedence over HF_ENDPOINT for simpler mirror config - Supports both full URLs (https://hf-mirror.com) and simple hostnames (hf-mirror.com) - Auto-adds https:// if no scheme is provided Closes mudler#8414 Signed-off-by: localai-bot <localai-bot@users.noreply.github.com>
1 parent 94539f3 commit fd7b2df

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

pkg/downloader/uri.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,24 @@ const (
4040
type URI string
4141

4242
// HF_ENDPOINT is the HuggingFace endpoint, can be overridden by setting the HF_ENDPOINT environment variable.
43+
// HF_MIRROR is an alternative way to set a mirror URL (e.g., hf-mirror.com).
44+
// If both are set, HF_ENDPOINT takes precedence.
4345
var HF_ENDPOINT string = loadConfig()
4446

4547
func loadConfig() string {
48+
// Check for HF_MIRROR first (simpler configuration for mirrors)
49+
HF_MIRROR := os.Getenv("HF_MIRROR")
50+
if HF_MIRROR != "" {
51+
// Normalize the mirror URL
52+
HF_MIRROR = strings.TrimRight(HF_MIRROR, "/")
53+
// Add https:// if no scheme is provided
54+
if !strings.HasPrefix(HF_MIRROR, "http://") && !strings.HasPrefix(HF_MIRROR, "https://") {
55+
HF_MIRROR = "https://" + HF_MIRROR
56+
}
57+
return HF_MIRROR
58+
}
59+
60+
// Fall back to HF_ENDPOINT
4661
HF_ENDPOINT := os.Getenv("HF_ENDPOINT")
4762
if HF_ENDPOINT == "" {
4863
HF_ENDPOINT = "https://huggingface.co"

0 commit comments

Comments
 (0)