11#include " model_del_cmd.h"
2- #include " cmd_info.h"
3- #include " config/yaml_config.h"
4- #include " utils/file_manager_utils.h"
5- #include " utils/modellist_utils.h"
2+ #include " utils/logging_utils.h"
63
74namespace commands {
8- bool ModelDelCmd::Exec (const std::string& model_handle) {
9- modellist_utils::ModelListUtils modellist_handler;
10- config::YamlHandler yaml_handler;
11-
12- try {
13- auto model_entry = modellist_handler.GetModelInfo (model_handle);
14- yaml_handler.ModelConfigFromFile (model_entry.path_to_model_yaml );
15- auto mc = yaml_handler.GetModelConfig ();
16- // Remove yaml file
17- std::filesystem::remove (model_entry.path_to_model_yaml );
18- // Remove model files if they are not imported locally
19- if (model_entry.branch_name != " imported" ) {
20- if (mc.files .size () > 0 ) {
21- if (mc.engine == " cortex.llamacpp" ) {
22- for (auto & file : mc.files ) {
23- std::filesystem::path gguf_p (file);
24- std::filesystem::remove (gguf_p);
25- }
26- } else {
27- std::filesystem::path f (mc.files [0 ]);
28- std::filesystem::remove_all (f);
29- }
30- } else {
31- CTL_WRN (" model config files are empty!" );
32- }
33- }
34-
35- // update model.list
36- if (modellist_handler.DeleteModelEntry (model_handle)) {
37- CLI_LOG (" The model " << model_handle << " was deleted" );
38- return true ;
39- } else {
40- CTL_ERR (" Could not delete model: " << model_handle);
41- return false ;
42- }
43- } catch (const std::exception& e) {
44- CLI_LOG (" Fail to delete model with ID '" + model_handle + " ': " + e.what ());
45- false ;
5+ void ModelDelCmd::Exec (const std::string& model_handle) {
6+ auto result = model_service_.DeleteModel (model_handle);
7+ if (result.has_error ()) {
8+ CLI_LOG (result.error ());
9+ } else {
10+ CLI_LOG (" Model " + model_handle + " deleted successfully" );
4611 }
4712}
48- } // namespace commands
13+ } // namespace commands
0 commit comments