Skip to content

Commit 8282414

Browse files
authored
chore(downloader): support hf.co and hf:// URIs (mudler#4677)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent d1d7ce8 commit 8282414

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pkg/downloader/uri.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ import (
2121
)
2222

2323
const (
24-
HuggingFacePrefix = "huggingface://"
25-
OCIPrefix = "oci://"
26-
OllamaPrefix = "ollama://"
27-
HTTPPrefix = "http://"
28-
HTTPSPrefix = "https://"
29-
GithubURI = "github:"
30-
GithubURI2 = "github://"
31-
LocalPrefix = "file://"
24+
HuggingFacePrefix = "huggingface://"
25+
HuggingFacePrefix1 = "hf://"
26+
HuggingFacePrefix2 = "hf.co/"
27+
OCIPrefix = "oci://"
28+
OllamaPrefix = "ollama://"
29+
HTTPPrefix = "http://"
30+
HTTPSPrefix = "https://"
31+
GithubURI = "github:"
32+
GithubURI2 = "github://"
33+
LocalPrefix = "file://"
3234
)
3335

3436
type URI string
@@ -127,6 +129,8 @@ func (u URI) LooksLikeURL() bool {
127129
return strings.HasPrefix(string(u), HTTPPrefix) ||
128130
strings.HasPrefix(string(u), HTTPSPrefix) ||
129131
strings.HasPrefix(string(u), HuggingFacePrefix) ||
132+
strings.HasPrefix(string(u), HuggingFacePrefix1) ||
133+
strings.HasPrefix(string(u), HuggingFacePrefix2) ||
130134
strings.HasPrefix(string(u), GithubURI) ||
131135
strings.HasPrefix(string(u), OllamaPrefix) ||
132136
strings.HasPrefix(string(u), OCIPrefix) ||
@@ -170,8 +174,10 @@ func (s URI) ResolveURL() string {
170174
projectPath := strings.Join(repoPath[2:], "/")
171175

172176
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/%s", org, project, branch, projectPath)
173-
case strings.HasPrefix(string(s), HuggingFacePrefix):
177+
case strings.HasPrefix(string(s), HuggingFacePrefix) || strings.HasPrefix(string(s), HuggingFacePrefix1) || strings.HasPrefix(string(s), HuggingFacePrefix2):
174178
repository := strings.Replace(string(s), HuggingFacePrefix, "", 1)
179+
repository = strings.Replace(repository, HuggingFacePrefix1, "", 1)
180+
repository = strings.Replace(repository, HuggingFacePrefix2, "", 1)
175181
// convert repository to a full URL.
176182
// e.g. TheBloke/Mixtral-8x7B-v0.1-GGUF/mixtral-8x7b-v0.1.Q2_K.gguf@main -> https://huggingface.co/TheBloke/Mixtral-8x7B-v0.1-GGUF/resolve/main/mixtral-8x7b-v0.1.Q2_K.gguf
177183
owner := strings.Split(repository, "/")[0]

0 commit comments

Comments
 (0)