Skip to content

Commit 6d090fc

Browse files
committed
remove redundant import
1 parent d9779ea commit 6d090fc

16 files changed

+297
-149
lines changed

engine/commands/model_get_cmd.cc

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44
#include <vector>
55
#include "cmd_info.h"
66
#include "config/yaml_config.h"
7-
#include "trantor/utils/Logger.h"
8-
#include "utils/cortex_utils.h"
97
#include "utils/file_manager_utils.h"
108
#include "utils/logging_utils.h"
119

1210
namespace commands {
1311

14-
ModelGetCmd::ModelGetCmd(std::string model_handle)
15-
: model_handle_(std::move(model_handle)) {}
16-
17-
void ModelGetCmd::Exec() {
12+
void ModelGetCmd::Exec(const std::string& model_handle) {
1813
auto models_path = file_manager_utils::GetModelsContainerPath();
1914
if (std::filesystem::exists(models_path) &&
2015
std::filesystem::is_directory(models_path)) {
21-
CmdInfo ci(model_handle_);
16+
CmdInfo ci(model_handle);
2217
std::string model_file =
2318
ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch;
2419
bool found_model = false;
@@ -149,4 +144,4 @@ void ModelGetCmd::Exec() {
149144
CLI_LOG("Model not found!");
150145
}
151146
}
152-
}; // namespace commands
147+
}; // namespace commands

engine/commands/model_get_cmd.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
#pragma once
22

3-
4-
#include <cmath> // For std::isnan
53
#include <string>
64
namespace commands {
75

86
class ModelGetCmd {
97
public:
10-
11-
ModelGetCmd(std::string model_handle);
12-
void Exec();
13-
14-
private:
15-
std::string model_handle_;
8+
void Exec(const std::string& model_handle);
169
};
17-
} // namespace commands
10+
} // namespace commands

engine/commands/run_cmd.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
#include "chat_cmd.h"
33
#include "cmd_info.h"
44
#include "config/yaml_config.h"
5-
#include "engine_install_cmd.h"
6-
#include "httplib.h"
7-
#include "model_pull_cmd.h"
85
#include "model_start_cmd.h"
96
#include "server_start_cmd.h"
10-
#include "trantor/utils/Logger.h"
11-
#include "utils/cortex_utils.h"
127
#include "utils/file_manager_utils.h"
138

149
namespace commands {
@@ -46,7 +41,7 @@ void RunCmd::Exec() {
4641
if (!commands::IsServerAlive(host_, port_)) {
4742
CLI_LOG("Starting server ...");
4843
commands::ServerStartCmd ssc;
49-
if(!ssc.Exec(host_, port_)) {
44+
if (!ssc.Exec(host_, port_)) {
5045
return;
5146
}
5247
}

engine/controllers/command_line_parser.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
138138
models_cmd->add_subcommand("get", "Get info of {model_id} locally");
139139
get_models_cmd->add_option("model_id", model_id, "");
140140
get_models_cmd->require_option();
141-
get_models_cmd->callback([&model_id]() {
142-
commands::ModelGetCmd command(model_id);
143-
command.Exec();
144-
});
141+
get_models_cmd->callback(
142+
[&model_id]() { commands::ModelGetCmd().Exec(model_id); });
145143

146144
auto model_del_cmd =
147145
models_cmd->add_subcommand("delete", "Delete a model by ID locally");
@@ -238,7 +236,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
238236
auto ps_cmd =
239237
app_.add_subcommand("ps", "Show running models and their status");
240238
ps_cmd->group(kSystemGroup);
241-
239+
242240
CLI11_PARSE(app_, argc, argv);
243241
if (argc == 1) {
244242
CLI_LOG(app_.help());

engine/e2e-test/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from test_cli_server_start import TestCliServerStart
1010
from test_cortex_update import TestCortexUpdate
1111
from test_create_log_folder import TestCreateLogFolder
12-
from test_cli_model_pull_direct_url import TestCliModelPullDirectUrl
1312

1413
if __name__ == "__main__":
1514
pytest.main([__file__, "-v"])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from test_runner import popen
2+
3+
4+
class TestCliModelPullCortexsoWithSelection:
5+
6+
def test_pull_model_from_cortexso_should_display_list_and_allow_user_to_choose(
7+
self,
8+
):
9+
stdout, stderr, return_code = popen(["pull", "tinyllama"], "1\n")
10+
11+
assert "Model tinyllama downloaded successfully!" in stdout
12+
assert return_code == 0
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import platform
2-
3-
import pytest
41
from test_runner import run
52

63

74
class TestCliModelPullDirectUrl:
85

9-
@pytest.mark.skipif(True, reason="Expensive test. Only test when needed.")
106
def test_model_pull_with_direct_url_should_be_success(self):
117
exit_code, output, error = run(
12-
"Pull model", ["pull", "https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/blob/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf"],
13-
timeout=None
8+
"Pull model",
9+
[
10+
"pull",
11+
"https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/blob/main/tinyllama-1.1b-chat-v0.3.Q2_K.gguf",
12+
],
13+
timeout=None,
1414
)
1515
assert exit_code == 0, f"Model pull failed with error: {error}"
1616
# TODO: verify that the model has been pull successfully
17-
# TODO: skip this test. since download model is taking too long
17+
# TODO: skip this test. since download model is taking too long
18+
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import platform
2-
31
import pytest
42
from test_runner import run
53

64

75
class TestCliModelPullCortexso:
86

9-
@pytest.mark.skipif(True, reason="Expensive test. Only test when needed.")
107
def test_model_pull_with_direct_url_should_be_success(self):
118
exit_code, output, error = run(
12-
"Pull model", ["pull", "tinyllama"],
13-
timeout=None
9+
"Pull model",
10+
["pull", "tinyllama"],
11+
timeout=None,
1412
)
1513
assert exit_code == 0, f"Model pull failed with error: {error}"
1614
# TODO: verify that the model has been pull successfully
17-
# TODO: skip this test. since download model is taking too long
15+
# TODO: skip this test. since download model is taking too long
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
from test_runner import popen
3+
4+
5+
class TestCliModelPullHuggingFaceRepository:
6+
7+
def test_model_pull_hugging_face_repository(self):
8+
"""
9+
Test pull model pervll/bge-reranker-v2-gemma-Q4_K_M-GGUF from issue #1017
10+
"""
11+
12+
stdout, stderr, return_code = popen(
13+
["pull", "pervll/bge-reranker-v2-gemma-Q4_K_M-GGUF"], "1\n"
14+
)
15+
16+
assert "downloaded successfully!" in stdout
17+
assert return_code == 0
18+
19+
def test_model_pull_hugging_face_not_gguf_should_failed_gracefully(self):
20+
"""
21+
When pull a model which is not GGUF, we stop and show a message to user
22+
"""
23+
24+
stdout, stderr, return_code = popen(["pull", "BAAI/bge-reranker-v2-m3"], "")
25+
assert (
26+
"Not a GGUF model. Currently, only GGUF single file is supported." in stdout
27+
)
28+
assert return_code == 0

engine/e2e-test/test_runner.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ def run(test_name: str, arguments: List[str], timeout=timeout) -> (int, str, str
3838
return result.returncode, result.stdout, result.stderr
3939

4040

41+
def popen(arguments: List[str], user_input: str) -> (int, str, str):
42+
# Start the process
43+
executable_path = getExecutablePath()
44+
process = subprocess.Popen(
45+
[executable_path] + arguments,
46+
stdin=subprocess.PIPE,
47+
stdout=subprocess.PIPE,
48+
stderr=subprocess.PIPE,
49+
text=True, # This ensures the input and output are treated as text
50+
)
51+
52+
# Send input and get output
53+
stdout, stderr = process.communicate(input=user_input)
54+
55+
# Get the return code
56+
return_code = process.returncode
57+
58+
return stdout, stderr, return_code
59+
60+
4161
# Start the API server
4262
# Wait for `Server started` message or failed
4363
def start_server() -> bool:
@@ -50,10 +70,10 @@ def start_server() -> bool:
5070
def start_server_nix() -> bool:
5171
executable = getExecutablePath()
5272
process = subprocess.Popen(
53-
[executable] + ['start', '-p', '3928'],
54-
stdout=subprocess.PIPE,
55-
stderr=subprocess.PIPE,
56-
text=True
73+
[executable] + ["start", "-p", "3928"],
74+
stdout=subprocess.PIPE,
75+
stderr=subprocess.PIPE,
76+
text=True,
5777
)
5878

5979
start_time = time.time()
@@ -80,7 +100,7 @@ def start_server_nix() -> bool:
80100
def start_server_windows() -> bool:
81101
executable = getExecutablePath()
82102
process = subprocess.Popen(
83-
[executable] + ['start', '-p', '3928'],
103+
[executable] + ["start", "-p", "3928"],
84104
stdout=subprocess.PIPE,
85105
stderr=subprocess.PIPE,
86106
text=True,

0 commit comments

Comments
 (0)