Skip to content

Commit 669d351

Browse files
committed
People search for ollama models using the web ui, this change allows one to copy the url from the browser and for it to be compatible with llama-run. Signed-off-by: Eric Curtin <[email protected]>
1 parent b636228 commit 669d351

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

examples/run/run.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -674,36 +674,28 @@ class LlamaData {
674674
}
675675

676676
int github_dl(const std::string & model, const std::string & bn) {
677-
std::string repository = model;
678-
std::string branch = "main";
679-
size_t at_pos = model.find('@');
677+
std::string repository = model;
678+
std::string branch = "main";
679+
const size_t at_pos = model.find('@');
680680
if (at_pos != std::string::npos) {
681681
repository = model.substr(0, at_pos);
682682
branch = model.substr(at_pos + 1);
683683
}
684684

685-
std::vector<std::string> repo_parts;
686-
size_t start = 0;
687-
for (size_t end = 0; (end = repository.find('/', start)) != std::string::npos; start = end + 1) {
688-
repo_parts.push_back(repository.substr(start, end - start));
689-
}
690-
691-
repo_parts.push_back(repository.substr(start));
685+
const std::vector<std::string> repo_parts = string_split(repository, "/");
692686
if (repo_parts.size() < 3) {
693687
printe("Invalid GitHub repository format\n");
694688
return 1;
695689
}
696690

697-
const std::string org = repo_parts[0];
698-
const std::string project = repo_parts[1];
699-
std::string project_path = repo_parts[2];
691+
const std::string & org = repo_parts[0];
692+
const std::string & project = repo_parts[1];
693+
std::string url =
694+
"https://raw.githubusercontent.com/" + org + "/" + project + "/" + branch + "/" + repo_parts[2];
700695
for (size_t i = 3; i < repo_parts.size(); ++i) {
701-
project_path += "/" + repo_parts[i];
696+
url += "/" + repo_parts[i];
702697
}
703698

704-
const std::string url =
705-
"https://raw.githubusercontent.com/" + org + "/" + project + "/" + branch + "/" + project_path;
706-
707699
return download(url, bn, true);
708700
}
709701

@@ -735,19 +727,20 @@ class LlamaData {
735727
}
736728

737729
const std::string bn = basename(model_);
738-
if (string_starts_with(model_, "hf://") || string_starts_with(model_, "huggingface://")) {
739-
rm_until_substring(model_, "://");
740-
ret = huggingface_dl(model_, bn);
741-
} else if (string_starts_with(model_, "hf.co/")) {
730+
if (string_starts_with(model_, "hf://") || string_starts_with(model_, "huggingface://") ||
731+
string_starts_with(model_, "hf.co/")) {
742732
rm_until_substring(model_, "hf.co/");
733+
rm_until_substring(model_, "://");
743734
ret = huggingface_dl(model_, bn);
744-
} else if (string_starts_with(model_, "https://") || string_starts_with(model_, "http://")) {
735+
} else if ((string_starts_with(model_, "https://") || string_starts_with(model_, "http://")) &&
736+
!string_starts_with(model_, "https://ollama.com/library/")) {
745737
ret = download(model_, bn, true);
746738
} else if (string_starts_with(model_, "github:") || string_starts_with(model_, "github://")) {
747-
rm_until_substring(model_, "github://");
748739
rm_until_substring(model_, "github:");
740+
rm_until_substring(model_, "://");
749741
ret = github_dl(model_, bn);
750742
} else { // ollama:// or nothing
743+
rm_until_substring(model_, "ollama.com/library/");
751744
rm_until_substring(model_, "://");
752745
ret = ollama_dl(model_, bn);
753746
}

0 commit comments

Comments
 (0)