Skip to content

Commit f211d1d

Browse files
authored
Treat hf.co/ prefix the same as hf:// (#11350)
ollama uses hf.co/ to specify huggingface prefix, like RamaLama uses hf:// Treat them similarly. Signed-off-by: Eric Curtin <[email protected]>
1 parent 955a6c2 commit f211d1d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

examples/run/run.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -634,20 +634,20 @@ class LlamaData {
634634
return path.substr(pos + 1);
635635
}
636636

637-
int remove_proto(std::string & model_) {
638-
const std::string::size_type pos = model_.find("://");
637+
int rm_until_substring(std::string & model_, const std::string & substring) {
638+
const std::string::size_type pos = model_.find(substring);
639639
if (pos == std::string::npos) {
640640
return 1;
641641
}
642642

643-
model_ = model_.substr(pos + 3); // Skip past "://"
643+
model_ = model_.substr(pos + substring.size()); // Skip past the substring
644644
return 0;
645645
}
646646

647647
int resolve_model(std::string & model_) {
648648
int ret = 0;
649649
if (string_starts_with(model_, "file://") || std::filesystem::exists(model_)) {
650-
remove_proto(model_);
650+
rm_until_substring(model_, "://");
651651

652652
return ret;
653653
}
@@ -656,13 +656,16 @@ class LlamaData {
656656
const std::vector<std::string> headers = { "--header",
657657
"Accept: application/vnd.docker.distribution.manifest.v2+json" };
658658
if (string_starts_with(model_, "hf://") || string_starts_with(model_, "huggingface://")) {
659-
remove_proto(model_);
659+
rm_until_substring(model_, "://");
660+
ret = huggingface_dl(model_, headers, bn);
661+
} else if (string_starts_with(model_, "hf.co/")) {
662+
rm_until_substring(model_, "hf.co/");
660663
ret = huggingface_dl(model_, headers, bn);
661664
} else if (string_starts_with(model_, "ollama://")) {
662-
remove_proto(model_);
665+
rm_until_substring(model_, "://");
663666
ret = ollama_dl(model_, headers, bn);
664667
} else if (string_starts_with(model_, "https://")) {
665-
download(model_, headers, bn, true);
668+
ret = download(model_, headers, bn, true);
666669
} else {
667670
ret = ollama_dl(model_, headers, bn);
668671
}

0 commit comments

Comments
 (0)