Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions engine/commands/engine_get_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ namespace commands {

void EngineGetCmd::Exec(const std::string& engine_name) const {
auto engine = engine_service_.GetEngineInfo(engine_name);
if (engine == std::nullopt) {
CLI_LOG("Engine " + engine_name + " is not supported!");
if (engine.has_error()) {
CLI_LOG(engine.error());
return;
}

auto version = engine->version.value_or("");
auto variant = engine->variant.value_or("");
tabulate::Table table;
table.add_row({"Name", "Supported Formats", "Version", "Status"});
table.add_row({"Name", "Supported Formats", "Version", "Variant", "Status"});
table.add_row(
{engine->product_name, engine->format, engine->version, engine->status});
{engine->product_name, engine->format, version, variant, engine->status});
std::cout << table << std::endl;
}
}; // namespace commands
11 changes: 7 additions & 4 deletions engine/commands/engine_list_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ bool EngineListCmd::Exec() {
auto status_list = engine_service.GetEngineInfoList();

tabulate::Table table;
table.add_row({"#", "Name", "Supported Formats", "Version", "Status"});
table.add_row(
{"#", "Name", "Supported Formats", "Version", "Variant", "Status"});
for (int i = 0; i < status_list.size(); i++) {
auto status = status_list[i];
auto engine_status = status_list[i];
std::string index = std::to_string(i + 1);
table.add_row({index, status.product_name, status.format, status.version,
status.status});
auto variant = engine_status.variant.value_or("");
auto version = engine_status.version.value_or("");
table.add_row({index, engine_status.product_name, engine_status.format,
version, variant, engine_status.status});
}

std::cout << table << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion engine/commands/engine_uninstall_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void EngineUninstallCmd::Exec(const std::string& engine) {
if (result.has_error()) {
CLI_LOG(result.error());
} else {
CLI_LOG("Engine uninstalled successfully");
CLI_LOG("Engine " + engine + " uninstalled successfully!");
}
}
}; // namespace commands
51 changes: 8 additions & 43 deletions engine/commands/model_del_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,48 +1,13 @@
#include "model_del_cmd.h"
#include "cmd_info.h"
#include "config/yaml_config.h"
#include "utils/file_manager_utils.h"
#include "utils/modellist_utils.h"
#include "utils/logging_utils.h"

namespace commands {
bool ModelDelCmd::Exec(const std::string& model_handle) {
modellist_utils::ModelListUtils modellist_handler;
config::YamlHandler yaml_handler;

try {
auto model_entry = modellist_handler.GetModelInfo(model_handle);
yaml_handler.ModelConfigFromFile(model_entry.path_to_model_yaml);
auto mc = yaml_handler.GetModelConfig();
// Remove yaml file
std::filesystem::remove(model_entry.path_to_model_yaml);
// Remove model files if they are not imported locally
if (model_entry.branch_name != "imported") {
if (mc.files.size() > 0) {
if (mc.engine == "cortex.llamacpp") {
for (auto& file : mc.files) {
std::filesystem::path gguf_p(file);
std::filesystem::remove(gguf_p);
}
} else {
std::filesystem::path f(mc.files[0]);
std::filesystem::remove_all(f);
}
} else {
CTL_WRN("model config files are empty!");
}
}

// update model.list
if (modellist_handler.DeleteModelEntry(model_handle)) {
CLI_LOG("The model " << model_handle << " was deleted");
return true;
} else {
CTL_ERR("Could not delete model: " << model_handle);
return false;
}
} catch (const std::exception& e) {
CLI_LOG("Fail to delete model with ID '" + model_handle + "': " + e.what());
false;
void ModelDelCmd::Exec(const std::string& model_handle) {
auto result = model_service_.DeleteModel(model_handle);
if (result.has_error()) {
CLI_LOG(result.error());
} else {
CLI_LOG("Model " + model_handle + " deleted successfully");
}
}
} // namespace commands
} // namespace commands
10 changes: 8 additions & 2 deletions engine/commands/model_del_cmd.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#pragma once

#include <string>
#include "services/model_service.h"

namespace commands {

class ModelDelCmd {
public:
bool Exec(const std::string& model_handle);
explicit ModelDelCmd() : model_service_{ModelService()} {};

void Exec(const std::string& model_handle);

private:
ModelService model_service_;
};
}
} // namespace commands
1 change: 0 additions & 1 deletion engine/commands/model_list_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "model_list_cmd.h"
#include <filesystem>
#include <iostream>
#include <tabulate/table.hpp>
#include <vector>
Expand Down
9 changes: 7 additions & 2 deletions engine/commands/model_pull_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#include "model_pull_cmd.h"
#include "utils/cortexso_parser.h"
#include "utils/logging_utils.h"

namespace commands {
void ModelPullCmd::Exec(const std::string& input) {
model_service_.DownloadModel(input);
auto result = model_service_.DownloadModel(input);
if (result.has_error()) {
CLI_LOG(result.error());
} else {
CLI_LOG("Model downloaded successfully!");
}
}
}; // namespace commands
9 changes: 4 additions & 5 deletions engine/commands/run_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ void RunCmd::Exec() {
// Download model if it does not exist
{
if (!modellist_handler.HasModel(model_handle_)) {
model_id = model_service_.DownloadModel(model_handle_);
if (!model_id.has_value()) {
CTL_ERR("Error: Could not get model_id from handle: " << model_handle_);
auto result = model_service_.DownloadModel(model_handle_);
if (result.has_error()) {
CTL_ERR("Error: " << result.error());
return;
} else {
CTL_INF("model_id: " << model_id.value());
}
CTL_INF("model_id: " << model_id.value());
}
}

Expand Down
7 changes: 3 additions & 4 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,13 @@ void CommandLineParser::SetupModelCommands() {
" models delete [model_id]");
model_del_cmd->group(kSubcommands);
model_del_cmd->add_option("model_id", cml_data_.model_id, "");
model_del_cmd->callback([this, model_del_cmd]() {
model_del_cmd->callback([&]() {
if (cml_data_.model_id.empty()) {
CLI_LOG("[model_id] is required\n");
CLI_LOG(model_del_cmd->help());
return;
};
commands::ModelDelCmd mdc;
mdc.Exec(cml_data_.model_id);
commands::ModelDelCmd().Exec(cml_data_.model_id);
});

std::string model_alias;
Expand Down Expand Up @@ -518,4 +517,4 @@ void CommandLineParser::ModelUpdate(CLI::App* parent) {
commands::ModelUpdCmd command(cml_data_.model_id);
command.Exec(cml_data_.model_update_options);
});
}
}
Loading
Loading