Skip to content

Commit

Permalink
Merge pull request #1227 from janhq/j/download-model-direct-url
Browse files Browse the repository at this point in the history
feat: download model with direct url
  • Loading branch information
namchuai authored Sep 17, 2024
2 parents d81c801 + 5d06c15 commit 6dcecef
Show file tree
Hide file tree
Showing 35 changed files with 620 additions and 442 deletions.
27 changes: 11 additions & 16 deletions engine/commands/engine_get_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@

namespace commands {

void EngineGetCmd::Exec() const {
CTL_INF("[EngineGetCmd] engine: " << engine_);

auto engine_service = EngineService();
try {
auto status = engine_service.GetEngineInfo(engine_);
tabulate::Table table;
table.add_row({"Name", "Supported Formats", "Version", "Status"});
table.add_row(
{status.product_name, status.format, status.version, status.status});
std::cout << table << std::endl;
} catch (const std::runtime_error& e) {
std::cerr << "Engine " << engine_ << " is not supported!" << "\n";
} catch (const std::exception& e) {
std::cerr << "Failed to get engine info for " << engine_ << ": " << e.what()
<< "\n";
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!");
return;
}

tabulate::Table table;
table.add_row({"Name", "Supported Formats", "Version", "Status"});
table.add_row(
{engine->product_name, engine->format, engine->version, engine->status});
std::cout << table << std::endl;
}
}; // namespace commands
8 changes: 4 additions & 4 deletions engine/commands/engine_get_cmd.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#pragma once

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

namespace commands {
class EngineGetCmd {
public:
EngineGetCmd(const std::string& engine) : engine_{engine} {};
explicit EngineGetCmd() : engine_service_{EngineService()} {};

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

private:
std::string engine_;
EngineService engine_service_;
};
} // namespace commands
220 changes: 0 additions & 220 deletions engine/commands/engine_init_cmd.cc

This file was deleted.

18 changes: 0 additions & 18 deletions engine/commands/engine_init_cmd.h

This file was deleted.

17 changes: 17 additions & 0 deletions engine/commands/engine_install_cmd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "engine_install_cmd.h"
// clang-format off
#include "utils/cortexso_parser.h"
#include "utils/archive_utils.h"
// clang-format on
#include "utils/cuda_toolkit_utils.h"
#include "utils/engine_matcher_utils.h"
#include "utils/logging_utils.h"

namespace commands {

void EngineInstallCmd::Exec(const std::string& engine,
const std::string& version) {
engine_service_.InstallEngine(engine, version);
CLI_LOG("Engine " << engine << " installed successfully!");
}
}; // namespace commands
17 changes: 17 additions & 0 deletions engine/commands/engine_install_cmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

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

namespace commands {

class EngineInstallCmd {
public:
explicit EngineInstallCmd() : engine_service_{EngineService()} {};

void Exec(const std::string& engine, const std::string& version = "latest");

private:
EngineService engine_service_;
};
} // namespace commands
16 changes: 3 additions & 13 deletions engine/commands/engine_uninstall_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@

namespace commands {

EngineUninstallCmd::EngineUninstallCmd(std::string engine)
: engine_{std::move(engine)} {}

void EngineUninstallCmd::Exec() const {
CTL_INF("Uninstall engine " + engine_);
auto engine_service = EngineService();

try {
engine_service.UninstallEngine(engine_);
CLI_LOG("Engine " << engine_ << " uninstalled successfully!")
} catch (const std::exception& e) {
CLI_LOG("Failed to uninstall engine " << engine_ << ": " << e.what());
}
void EngineUninstallCmd::Exec(const std::string& engine) {
engine_service_.UninstallEngine(engine);
CLI_LOG("Engine " << engine << " uninstalled successfully!");
}
}; // namespace commands
7 changes: 4 additions & 3 deletions engine/commands/engine_uninstall_cmd.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

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

namespace commands {
class EngineUninstallCmd {
public:
EngineUninstallCmd(std::string engine);
explicit EngineUninstallCmd() : engine_service_{EngineService()} {};

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

private:
std::string engine_;
EngineService engine_service_;
};
} // namespace commands
6 changes: 1 addition & 5 deletions engine/commands/model_list_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// clang-format off
#include "utils/cortex_utils.h"
// clang-format on
#include "model_list_cmd.h"
#include <filesystem>
#include <iostream>
#include <tabulate/table.hpp>
#include <vector>
#include "config/yaml_config.h"
#include "trantor/utils/Logger.h"
#include "utils/file_manager_utils.h"
#include "utils/logging_utils.h"

Expand Down Expand Up @@ -57,4 +53,4 @@ void ModelListCmd::Exec() {
std::cout << table << std::endl;
}
}
}; // namespace commands
}; // namespace commands
Loading

0 comments on commit 6dcecef

Please sign in to comment.