mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 10:35:01 +00:00
chore(downloader): support hf.co and hf:// URIs (#4677)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
d1d7ce83d4
commit
8282414583
1 changed files with 15 additions and 9 deletions
|
@ -22,6 +22,8 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HuggingFacePrefix = "huggingface://"
|
HuggingFacePrefix = "huggingface://"
|
||||||
|
HuggingFacePrefix1 = "hf://"
|
||||||
|
HuggingFacePrefix2 = "hf.co/"
|
||||||
OCIPrefix = "oci://"
|
OCIPrefix = "oci://"
|
||||||
OllamaPrefix = "ollama://"
|
OllamaPrefix = "ollama://"
|
||||||
HTTPPrefix = "http://"
|
HTTPPrefix = "http://"
|
||||||
|
@ -127,6 +129,8 @@ func (u URI) LooksLikeURL() bool {
|
||||||
return strings.HasPrefix(string(u), HTTPPrefix) ||
|
return strings.HasPrefix(string(u), HTTPPrefix) ||
|
||||||
strings.HasPrefix(string(u), HTTPSPrefix) ||
|
strings.HasPrefix(string(u), HTTPSPrefix) ||
|
||||||
strings.HasPrefix(string(u), HuggingFacePrefix) ||
|
strings.HasPrefix(string(u), HuggingFacePrefix) ||
|
||||||
|
strings.HasPrefix(string(u), HuggingFacePrefix1) ||
|
||||||
|
strings.HasPrefix(string(u), HuggingFacePrefix2) ||
|
||||||
strings.HasPrefix(string(u), GithubURI) ||
|
strings.HasPrefix(string(u), GithubURI) ||
|
||||||
strings.HasPrefix(string(u), OllamaPrefix) ||
|
strings.HasPrefix(string(u), OllamaPrefix) ||
|
||||||
strings.HasPrefix(string(u), OCIPrefix) ||
|
strings.HasPrefix(string(u), OCIPrefix) ||
|
||||||
|
@ -170,8 +174,10 @@ func (s URI) ResolveURL() string {
|
||||||
projectPath := strings.Join(repoPath[2:], "/")
|
projectPath := strings.Join(repoPath[2:], "/")
|
||||||
|
|
||||||
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/%s", org, project, branch, projectPath)
|
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/%s", org, project, branch, projectPath)
|
||||||
case strings.HasPrefix(string(s), HuggingFacePrefix):
|
case strings.HasPrefix(string(s), HuggingFacePrefix) || strings.HasPrefix(string(s), HuggingFacePrefix1) || strings.HasPrefix(string(s), HuggingFacePrefix2):
|
||||||
repository := strings.Replace(string(s), HuggingFacePrefix, "", 1)
|
repository := strings.Replace(string(s), HuggingFacePrefix, "", 1)
|
||||||
|
repository = strings.Replace(repository, HuggingFacePrefix1, "", 1)
|
||||||
|
repository = strings.Replace(repository, HuggingFacePrefix2, "", 1)
|
||||||
// convert repository to a full URL.
|
// convert repository to a full URL.
|
||||||
// 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
|
// 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
|
||||||
owner := strings.Split(repository, "/")[0]
|
owner := strings.Split(repository, "/")[0]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue