@@ -674,36 +674,27 @@ class LlamaData {
674
674
}
675
675
676
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 (' @' );
677
+ std::string repository = model;
678
+ std::string branch = " main" ;
679
+ const size_t at_pos = model.find (' @' );
680
680
if (at_pos != std::string::npos) {
681
681
repository = model.substr (0 , at_pos);
682
682
branch = model.substr (at_pos + 1 );
683
683
}
684
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));
685
+ const std::vector<std::string> repo_parts = string_split (repository, " /" );
692
686
if (repo_parts.size () < 3 ) {
693
687
printe (" Invalid GitHub repository format\n " );
694
688
return 1 ;
695
689
}
696
690
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];
691
+ const std::string & org = repo_parts[0 ];
692
+ const std::string & project = repo_parts[1 ];
693
+ std::string url = " https://raw.githubusercontent.com/ " + org + " / " + project + " / " + branch ;
694
+ for (size_t i = 2 ; i < repo_parts.size (); ++i) {
695
+ url += " /" + repo_parts[i];
702
696
}
703
697
704
- const std::string url =
705
- " https://raw.githubusercontent.com/" + org + " /" + project + " /" + branch + " /" + project_path;
706
-
707
698
return download (url, bn, true );
708
699
}
709
700
@@ -735,19 +726,20 @@ class LlamaData {
735
726
}
736
727
737
728
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/" )) {
729
+ if (string_starts_with (model_, " hf://" ) || string_starts_with (model_, " huggingface://" ) ||
730
+ string_starts_with (model_, " hf.co/" )) {
742
731
rm_until_substring (model_, " hf.co/" );
732
+ rm_until_substring (model_, " ://" );
743
733
ret = huggingface_dl (model_, bn);
744
- } else if (string_starts_with (model_, " https://" ) || string_starts_with (model_, " http://" )) {
734
+ } else if ((string_starts_with (model_, " https://" ) || string_starts_with (model_, " http://" )) &&
735
+ !string_starts_with (model_, " https://ollama.com/library/" )) {
745
736
ret = download (model_, bn, true );
746
737
} else if (string_starts_with (model_, " github:" ) || string_starts_with (model_, " github://" )) {
747
- rm_until_substring (model_, " github://" );
748
738
rm_until_substring (model_, " github:" );
739
+ rm_until_substring (model_, " ://" );
749
740
ret = github_dl (model_, bn);
750
741
} else { // ollama:// or nothing
742
+ rm_until_substring (model_, " ollama.com/library/" );
751
743
rm_until_substring (model_, " ://" );
752
744
ret = ollama_dl (model_, bn);
753
745
}
0 commit comments