Skip to content

Commit 4ded7c5

Browse files
ericcurtinNeoZhangJianyu
authored andcommitted
Add github protocol pulling and http:// (ggml-org#11465)
As pulling protocols to llama-run Signed-off-by: Eric Curtin <[email protected]>
1 parent 4e9762c commit 4ded7c5

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

examples/run/run.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,40 @@ class LlamaData {
673673
return download(blob_url, bn, true, headers);
674674
}
675675

676+
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('@');
680+
if (at_pos != std::string::npos) {
681+
repository = model.substr(0, at_pos);
682+
branch = model.substr(at_pos + 1);
683+
}
684+
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));
692+
if (repo_parts.size() < 3) {
693+
printe("Invalid GitHub repository format\n");
694+
return 1;
695+
}
696+
697+
const std::string org = repo_parts[0];
698+
const std::string project = repo_parts[1];
699+
std::string project_path = repo_parts[2];
700+
for (size_t i = 3; i < repo_parts.size(); ++i) {
701+
project_path += "/" + repo_parts[i];
702+
}
703+
704+
const std::string url =
705+
"https://raw.githubusercontent.com/" + org + "/" + project + "/" + branch + "/" + project_path;
706+
707+
return download(url, bn, true);
708+
}
709+
676710
std::string basename(const std::string & path) {
677711
const size_t pos = path.find_last_of("/\\");
678712
if (pos == std::string::npos) {
@@ -707,8 +741,12 @@ class LlamaData {
707741
} else if (string_starts_with(model_, "hf.co/")) {
708742
rm_until_substring(model_, "hf.co/");
709743
ret = huggingface_dl(model_, bn);
710-
} else if (string_starts_with(model_, "https://")) {
744+
} else if (string_starts_with(model_, "https://") || string_starts_with(model_, "http://")) {
711745
ret = download(model_, bn, true);
746+
} else if (string_starts_with(model_, "github:") || string_starts_with(model_, "github://")) {
747+
rm_until_substring(model_, "github://");
748+
rm_until_substring(model_, "github:");
749+
ret = github_dl(model_, bn);
712750
} else { // ollama:// or nothing
713751
rm_until_substring(model_, "://");
714752
ret = ollama_dl(model_, bn);

0 commit comments

Comments
 (0)