MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / common_params_handle_model

Function common_params_handle_model

smallthinker/common/arg.cpp:756–817  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

754};
755
756static handle_model_result common_params_handle_model(
757 struct common_params_model & model,
758 const std::string & bearer_token,
759 const std::string & model_path_default,
760 bool offline) {
761 handle_model_result result;
762 // handle pre-fill default model path and url based on hf_repo and hf_file
763 {
764 if (!model.hf_repo.empty()) {
765 // short-hand to avoid specifying --hf-file -> default it to --model
766 if (model.hf_file.empty()) {
767 if (model.path.empty()) {
768 auto auto_detected = common_get_hf_file(model.hf_repo, bearer_token, offline);
769 if (auto_detected.repo.empty() || auto_detected.ggufFile.empty()) {
770 exit(1); // built without CURL, error message already printed
771 }
772 model.hf_repo = auto_detected.repo;
773 model.hf_file = auto_detected.ggufFile;
774 if (!auto_detected.mmprojFile.empty()) {
775 result.found_mmproj = true;
776 result.mmproj.hf_repo = model.hf_repo;
777 result.mmproj.hf_file = auto_detected.mmprojFile;
778 }
779 } else {
780 model.hf_file = model.path;
781 }
782 }
783
784 std::string model_endpoint = get_model_endpoint();
785 model.url = model_endpoint + model.hf_repo + "/resolve/main/" + model.hf_file;
786 // make sure model path is present (for caching purposes)
787 if (model.path.empty()) {
788 // this is to avoid different repo having same file name, or same file name in different subdirs
789 std::string filename = model.hf_repo + "_" + model.hf_file;
790 // to make sure we don't have any slashes in the filename
791 string_replace_all(filename, "/", "_");
792 model.path = fs_get_cache_file(filename);
793 }
794
795 } else if (!model.url.empty()) {
796 if (model.path.empty()) {
797 auto f = string_split<std::string>(model.url, '#').front();
798 f = string_split<std::string>(f, '?').front();
799 model.path = fs_get_cache_file(string_split<std::string>(f, '/').back());
800 }
801
802 } else if (model.path.empty()) {
803 model.path = model_path_default;
804 }
805 }
806
807 // then, download it if needed
808 if (!model.url.empty()) {
809 bool ok = common_download_model(model, bearer_token, offline);
810 if (!ok) {
811 LOG_ERR("error: failed to download model from %s\n", model.url.c_str());
812 exit(1);
813 }

Callers 1

common_params_parse_exFunction · 0.85

Calls 7

common_get_hf_fileFunction · 0.85
get_model_endpointFunction · 0.85
fs_get_cache_fileFunction · 0.85
common_download_modelFunction · 0.85
string_replace_allFunction · 0.70
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected