Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 913dbfb

Browse files
committed
update
1 parent 578355d commit 913dbfb

File tree

7 files changed

+59
-28
lines changed

7 files changed

+59
-28
lines changed

engine/cli/commands/engine_install_cmd.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ bool EngineInstallCmd::Exec(const std::string& engine,
123123
"v1",
124124
"engines",
125125
engine,
126+
"install",
126127
},
127128
};
128129
Json::Value body;
@@ -164,6 +165,7 @@ bool EngineInstallCmd::Exec(const std::string& engine,
164165
"v1",
165166
"engines",
166167
engine,
168+
"install",
167169
},
168170
};
169171

engine/cli/commands/engine_uninstall_cmd.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ void EngineUninstallCmd::Exec(const std::string& host, int port,
1717
}
1818
}
1919

20-
auto url = url_parser::Url{.protocol = "http",
21-
.host = host + ":" + std::to_string(port),
22-
.pathParams = {"v1", "engines", engine}};
20+
auto url =
21+
url_parser::Url{.protocol = "http",
22+
.host = host + ":" + std::to_string(port),
23+
.pathParams = {"v1", "engines", engine, "install"}};
2324

2425
auto result = curl_utils::SimpleDeleteJson(url.ToFullPath());
2526
if (result.has_error()) {

engine/controllers/engines.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ void Engines::SetDefaultEngineVariant(
243243
const HttpRequestPtr& req,
244244
std::function<void(const HttpResponsePtr&)>&& callback,
245245
const std::string& engine) {
246+
auto json_obj = req->getJsonObject();
247+
if (json_obj == nullptr) {
248+
Json::Value res;
249+
res["message"] = "Request body is required";
250+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(res);
251+
resp->setStatusCode(k400BadRequest);
252+
callback(resp);
253+
return;
254+
}
255+
246256
auto variant = (*(req->getJsonObject())).get("variant", "").asString();
247257
if (variant.empty()) {
248258
Json::Value ret;

engine/controllers/engines.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ class Engines : public drogon::HttpController<Engines, false> {
1313
METHOD_LIST_BEGIN
1414

1515
// install engine
16-
METHOD_ADD(Engines::InstallEngine, "/{1}", Options, Post);
17-
ADD_METHOD_TO(Engines::InstallEngine, "/v1/engines/{1}", Options, Post);
16+
METHOD_ADD(Engines::InstallEngine, "/{1}/install", Options, Post);
17+
ADD_METHOD_TO(Engines::InstallEngine, "/v1/engines/{1}/install", Options,
18+
Post);
1819

1920
// uninstall engine
20-
METHOD_ADD(Engines::UninstallEngine, "/{1}", Options, Delete);
21-
ADD_METHOD_TO(Engines::UninstallEngine, "/v1/engines/{1}", Options, Delete);
21+
METHOD_ADD(Engines::UninstallEngine, "/{1}/install", Options, Delete);
22+
ADD_METHOD_TO(Engines::UninstallEngine, "/v1/engines/{1}/install", Options,
23+
Delete);
2224

2325
// set default engine
2426
METHOD_ADD(Engines::SetDefaultEngineVariant, "/{1}/default", Options, Post);

engine/e2e-test/test_api_engine_install.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ def setup_and_teardown(self):
1818
stop_server()
1919

2020
def test_engines_install_llamacpp_should_be_successful(self):
21-
response = requests.post("http://localhost:3928/v1/engines/llama-cpp")
21+
response = requests.post("http://localhost:3928/v1/engines/llama-cpp/install")
2222
assert response.status_code == 200
2323

2424
def test_engines_install_llamacpp_specific_version_and_variant(self):
25+
data = {"version": "v0.1.35-27.10.24", "variant": "linux-amd64-avx-cuda-11-7"}
2526
response = requests.post(
26-
"http://localhost:3928/v1/engines/llama-cpp?version=v0.1.35-27.10.24&variant=linux-amd64-avx-cuda-11-7"
27+
"http://localhost:3928/v1/engines/llama-cpp/install", json=data
2728
)
2829
assert response.status_code == 200
2930

3031
def test_engines_install_llamacpp_specific_version_and_null_variant(self):
32+
data = {"version": "v0.1.35-27.10.24"}
3133
response = requests.post(
32-
"http://localhost:3928/v1/engines/llama-cpp?version=v0.1.35-27.10.24"
34+
"http://localhost:3928/v1/engines/llama-cpp/install", json=data
3335
)
3436
assert response.status_code == 200
Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import pytest
22
import requests
3-
from test_runner import start_server, stop_server
3+
from test_runner import (
4+
run,
5+
start_server,
6+
stop_server,
7+
wait_for_websocket_download_success_event,
8+
)
49

510

611
class TestApiEngineUninstall:
@@ -18,47 +23,56 @@ def setup_and_teardown(self):
1823
stop_server()
1924

2025
def test_engines_uninstall_llamacpp_should_be_successful(self):
21-
# install first
22-
requests.post("http://localhost:3928/v1/engines/llama-cpp")
23-
24-
response = requests.delete("http://localhost:3928/v1/engines/llama-cpp")
26+
# install first, using cli for synchronously
27+
run(
28+
"Install Engine",
29+
["engines", "install", "llama-cpp"],
30+
timeout=120,
31+
capture=False,
32+
)
33+
response = requests.delete("http://localhost:3928/v1/engines/llama-cpp/install")
2534
assert response.status_code == 200
2635

2736
def test_engines_uninstall_llamacpp_with_only_version_should_be_failed(self):
2837
# install first
29-
install_response = requests.post(
30-
"http://localhost:3928/v1/engines/llama-cpp?version=v0.1.35"
38+
run(
39+
"Install Engine",
40+
["engines", "install", "llama-cpp", "-v", "v0.1.35"],
41+
timeout=None,
42+
capture=False,
3143
)
32-
assert install_response.status_code == 200
3344

45+
data = {"version": "v0.1.35"}
3446
response = requests.delete(
35-
"http://localhost:3928/v1/engines/llama-cpp?version=v0.1.35"
47+
"http://localhost:3928/v1/engines/llama-cpp/install", json=data
3648
)
3749
assert response.status_code == 400
3850
assert response.json()["message"] == "No variant provided"
3951

40-
def test_engines_uninstall_llamacpp_with_variant_should_be_successful(self):
52+
@pytest.mark.asyncio
53+
async def test_engines_uninstall_llamacpp_with_variant_should_be_successful(self):
4154
# install first
55+
data = {"variant": "mac-arm64"}
4256
install_response = requests.post(
43-
"http://localhost:3928/v1/engines/llama-cpp?variant=mac-arm64"
57+
"http://127.0.0.1:3928/v1/engines/llama-cpp/install", json=data
4458
)
59+
await wait_for_websocket_download_success_event(timeout=120)
4560
assert install_response.status_code == 200
4661

47-
response = requests.delete(
48-
"http://localhost:3928/v1/engines/llama-cpp?variant=mac-arm64"
49-
)
62+
response = requests.delete("http://127.0.0.1:3928/v1/engines/llama-cpp/install")
5063
assert response.status_code == 200
5164

5265
def test_engines_uninstall_llamacpp_with_specific_variant_and_version_should_be_successful(
5366
self,
5467
):
68+
data = {"variant": "mac-arm64", "version": "v0.1.35"}
5569
# install first
5670
install_response = requests.post(
57-
"http://localhost:3928/v1/engines/llama-cpp?variant=mac-arm64&version=v0.1.35"
71+
"http://localhost:3928/v1/engines/llama-cpp/install", json=data
5872
)
5973
assert install_response.status_code == 200
6074

6175
response = requests.delete(
62-
"http://localhost:3928/v1/engines/llama-cpp?variant=mac-arm64&version=v0.1.35"
76+
"http://localhost:3928/v1/engines/llama-cpp/install", json=data
6377
)
6478
assert response.status_code == 200

engine/e2e-test/test_cli_engine_uninstall.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def setup_and_teardown(self):
2424

2525
@pytest.mark.asyncio
2626
async def test_engines_uninstall_llamacpp_should_be_successfully(self):
27-
requests.post("http://127.0.0.1:3928/v1/engines/llama-cpp")
28-
await wait_for_websocket_download_success_event(timeout=None)
27+
requests.post("http://127.0.0.1:3928/v1/engines/llama-cpp/install")
28+
await wait_for_websocket_download_success_event(timeout=120)
2929
exit_code, output, error = run(
3030
"Uninstall engine", ["engines", "uninstall", "llama-cpp"]
3131
)

0 commit comments

Comments
 (0)