\brief Pull the model \param model_tag the model tag \param force_redownload true if the model should be downloaded even if it is already downloaded \return true if the model is downloaded, false otherwise
| 88 | /// \param force_redownload true if the model should be downloaded even if it is already downloaded |
| 89 | /// \return true if the model is downloaded, false otherwise |
| 90 | bool ModelDownloader::pull_model(const std::string& model_tag, bool force_redownload) { |
| 91 | try { |
| 92 | // Get model info |
| 93 | auto [new_model_tag, model_info] = supported_models.get_model_info(model_tag); |
| 94 | std::string model_name = model_info["name"]; |
| 95 | std::string base_url = model_info["url"]; |
| 96 | |
| 97 | header_print("FLM", "Model: " + new_model_tag); |
| 98 | header_print("FLM", "Name: " + model_name); |
| 99 | |
| 100 | // Check if model is already downloaded |
| 101 | if (!force_redownload && is_model_downloaded(new_model_tag)) { |
| 102 | header_print("FLM", "Model already downloaded. Use --force to re-download."); |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | // If force, verify existing files and remove only corrupted ones, |
| 107 | // instead of wiping the whole model directory. Files that pass |
| 108 | // verification will be reused; missing/corrupted ones get re-downloaded. |
| 109 | if (force_redownload) { |
| 110 | verify_and_clean_files(new_model_tag); |
| 111 | } |
| 112 | |
| 113 | // Get missing files |
| 114 | auto missing_files = get_missing_files(new_model_tag); |
| 115 | if (missing_files.empty() && !force_redownload) { |
| 116 | header_print("FLM", "All files already present."); |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | if (!missing_files.empty()) { |
| 121 | header_print("FLM", "Missing files (" + std::to_string(missing_files.size()) + "):"); |
| 122 | for (const auto& file : missing_files) { |
| 123 | std::cout << " - " << file << std::endl; |
| 124 | } |
| 125 | } else { |
| 126 | header_print("FLM", "All required files are present."); |
| 127 | } |
| 128 | |
| 129 | // Show present files if any |
| 130 | auto present_files = get_present_files(new_model_tag); |
| 131 | if (!present_files.empty()) { |
| 132 | header_print("FLM", "Present files (" + std::to_string(present_files.size()) + "):"); |
| 133 | for (const auto& file : present_files) { |
| 134 | std::cout << " - " << file << std::endl; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // Build download list |
| 139 | auto download_list = build_download_list(new_model_tag); |
| 140 | auto downloads = download_list.first; |
| 141 | float sum_fize_size = download_list.second; |
| 142 | if (downloads.empty()) { |
| 143 | header_print("FLM", "No files to download for model: " + new_model_tag); |
| 144 | return true; // Return true since all files are already present |
| 145 | } |
| 146 | |
| 147 | header_print("FLM", "Downloading " + std::to_string(downloads.size()) + " missing files..."); |
no test coverage detected