| 313 | } |
| 314 | |
| 315 | int ModelManager::DeleteModel(const std::string &model_name) { |
| 316 | if (model_name.empty()) { |
| 317 | mnncli::UserInterface::ShowError("Model name is required", |
| 318 | "Usage: mnncli delete <name>"); |
| 319 | return 1; |
| 320 | } |
| 321 | |
| 322 | LOG_INFO("Deleting model: " + model_name); |
| 323 | try { |
| 324 | // Get configuration |
| 325 | auto &config_mgr = ConfigManager::GetInstance(); |
| 326 | auto config = config_mgr.LoadConfig(); |
| 327 | std::string cache_dir = config.cache_dir; |
| 328 | if (cache_dir.empty()) { |
| 329 | cache_dir = mnncli::kCachePath; |
| 330 | } |
| 331 | |
| 332 | LOG_DEBUG_TAG("ModelManager::DeleteModel: cache_dir = " + cache_dir, "ModelManager"); |
| 333 | |
| 334 | // Get ModelDownloadManager instance |
| 335 | auto &download_manager = |
| 336 | mnn::downloader::ModelDownloadManager::GetInstance(cache_dir); |
| 337 | |
| 338 | // Get full model_id using ModelNameUtils |
| 339 | mnn::downloader::Config downloader_config; |
| 340 | downloader_config.cache_dir = config.cache_dir; |
| 341 | downloader_config.download_provider = config.download_provider; |
| 342 | std::string model_id = mnn::downloader::ModelNameUtils::GetFullModelId(model_name, downloader_config); |
| 343 | LOG_DEBUG_TAG("Model ID: " + model_id, "ModelManager"); |
| 344 | LOG_DEBUG_TAG("Calling ModelDownloadManager::DeleteRepo with model_id = " + model_id, "ModelManager"); |
| 345 | |
| 346 | // Use DeleteRepo to properly delete the model |
| 347 | bool deleted = download_manager.DeleteRepo(model_id); |
| 348 | |
| 349 | LOG_DEBUG_TAG("ModelDownloadManager::DeleteRepo returned: " + std::string(deleted ? "true" : "false"), "ModelManager"); |
| 350 | |
| 351 | if (deleted) { |
| 352 | mnncli::UserInterface::ShowSuccess("Model deleted successfully: " + |
| 353 | model_name); |
| 354 | } else { |
| 355 | mnncli::UserInterface::ShowError("Model not found: " + model_name); |
| 356 | return 1; |
| 357 | } |
| 358 | } catch (const std::exception &e) { |
| 359 | mnncli::UserInterface::ShowError("Failed to delete model: " + |
| 360 | std::string(e.what())); |
| 361 | return 1; |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | int ModelManager::ShowModelInfo(const std::string &model_name, bool verbose) { |
| 367 | if (model_name.empty()) { |
nothing calls this directly
no test coverage detected