| 134 | } |
| 135 | |
| 136 | int ModelManager::DownloadModel(const std::string &model_name, bool verbose, |
| 137 | const std::string &cache_dir_override) { |
| 138 | if (model_name.empty()) { |
| 139 | mnncli::UserInterface::ShowError("Model name is required", |
| 140 | "Usage: mnncli model download <name>"); |
| 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | LOG_INFO("Downloading model: " + model_name); |
| 145 | |
| 146 | // Get current configuration |
| 147 | auto &config_mgr = ConfigManager::GetInstance(); |
| 148 | auto config = config_mgr.LoadConfig(); |
| 149 | |
| 150 | // Show which download provider will be used |
| 151 | LOG_INFO("Using download provider: " + config.download_provider); |
| 152 | |
| 153 | // Early validation for obviously invalid model names |
| 154 | if (!IsValidModelName(model_name)) { |
| 155 | mnncli::UserInterface::ShowError("Invalid model name format: '" + |
| 156 | model_name + "'"); |
| 157 | std::cout << "\n💡 Valid model name formats:\n"; |
| 158 | std::cout |
| 159 | << " • Simple name (e.g., 'qwen-7b') - will search in repository\n"; |
| 160 | std::cout << " • Full ID (e.g., 'Qwen/Qwen-7B-Chat') - direct download\n"; |
| 161 | std::cout << " • Prefixed ID (e.g., 'hf:Qwen/Qwen-7B-Chat') - specify " |
| 162 | "provider\n"; |
| 163 | std::cout << "\n💡 Try:\n"; |
| 164 | std::cout << " • Use 'mnncli search " << model_name |
| 165 | << "' to find available models\n"; |
| 166 | std::cout << " • Use 'mnncli list' to see downloaded models\n"; |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | try { |
| 171 | // Get cache directory from override, config, or use default |
| 172 | std::string cache_dir; |
| 173 | if (!cache_dir_override.empty()) { |
| 174 | cache_dir = cache_dir_override; |
| 175 | } else { |
| 176 | cache_dir = config.cache_dir; |
| 177 | if (cache_dir.empty()) { |
| 178 | cache_dir = config_mgr.GetBaseCacheDir(); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Create download manager instance |
| 183 | auto &download_manager = |
| 184 | mnncli::ModelDownloadManager::GetInstance(cache_dir); |
| 185 | |
| 186 | // Create CLI download listener for user feedback |
| 187 | CLIDownloadListener cli_listener; |
| 188 | download_manager.AddListener(&cli_listener); |
| 189 | |
| 190 | // Use ModelRepository to get the correct model ID for download |
| 191 | std::string model_id; |
| 192 | std::string source = config.download_provider; |
| 193 |
nothing calls this directly
no test coverage detected