Skip to content

Commit b682f5c

Browse files
committed
Merge branch 'dev' of github.com:janhq/nitro into fix/add-dll-search-path
2 parents 2ddfe7a + 9391650 commit b682f5c

40 files changed

+478
-275
lines changed

.github/workflows/cortex-build.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: CI Cortex Release
22

33
on:
44
push:
5-
tags: ["v[0-9]+.[0-9]+.[0-9]+", "v[0-9]+.[0-9]+.[0-9]+-*", "!v[0-9]+.[0-9]+.[0-9]+-cortex-js"]
5+
tags: ["v[0-9]+.[0-9]+.[0-9]+", "v[0-9]+.[0-9]+.[0-9]+-*", "!v[0-9]+.[0-9]+.[0-9]+-cortex-js", "!v[0-9]+.[0-9]+.[0-9]+-[0-9]+-cortex-js"]
66
paths: ["cortex-cpp/**", "cortex-js/**"]
77
workflow_dispatch:
88

@@ -187,6 +187,13 @@ jobs:
187187
rm package.json
188188
mv package-tmp.json package.json
189189
190+
- name: Remove build build-deps and build folder for windows
191+
if: runner.os == 'Windows'
192+
run: |
193+
cd cortex-cpp
194+
Remove-Item -Recurse -Force build
195+
Remove-Item -Recurse -Force build-deps
196+
190197
# build prebuilds
191198
- name: Build Prebuilds
192199
working-directory: cortex-cpp
@@ -207,7 +214,7 @@ jobs:
207214
asset_content_type: application/gzip
208215

209216
# Setup .npmrc file to publish to npm - upload only once
210-
- run: npm publish --access public
217+
- run: rm -rf build-deps && rm -rf build && rm -rf prebuilds && npm publish --access public
211218
continue-on-error: true
212219
if: runner.os == 'linux'
213220
env:
@@ -219,14 +226,14 @@ jobs:
219226
build-cortex-single-binary:
220227
runs-on: ${{ matrix.runs-on }}
221228
needs: [create-draft-release, build-and-test]
222-
timeout-minutes: 20
229+
timeout-minutes: 40
223230
strategy:
224231
fail-fast: false
225232
matrix:
226233
include:
227234
- os: "linux"
228235
name: "amd64"
229-
runs-on: "ubuntu-latest"
236+
runs-on: "ubuntu-20-04"
230237

231238
- os: "windows"
232239
name: "amd64"
@@ -315,14 +322,14 @@ jobs:
315322
which cp
316323
which mv
317324
npm install -g cpx
318-
npx cpx ./dist/cortexso-macos ./
319-
mv cortexso-macos cortex
325+
npx cpx ./dist/cortexso ./
326+
mv cortexso cortex
320327
321328
- name: Code Signing macOS
322329
if: runner.os == 'macOS'
323330
run: |
324331
cd cortex-js
325-
./dist/cortexso-macos --help
332+
./dist/cortexso --help
326333
echo "--------"
327334
./cortex --help
328335
make codesign-binary CODE_SIGN=true DEVELOPER_ID="${{ secrets.DEVELOPER_ID }}"

.github/workflows/cortex-js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Publish cortex js Package to npmjs
22
on:
33
push:
4-
tags: ["v[0-9]+.[0-9]+.[0-9]+-cortex-js"]
4+
tags: ["v[0-9]+.[0-9]+.[0-9]+-cortex-js", "v[0-9]+.[0-9]+.[0-9]+-[0-9]+-cortex-js"]
55
paths:
66
[
77
"cortex-js/**",

cortex-cpp/addon.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ static Napi::Env* s_env = nullptr;
2727
void start(const int port = 3929) {
2828
int thread_num = 1;
2929
std::string host = "127.0.0.1";
30-
std::string uploads_folder_path;
3130
int logical_cores = std::thread::hardware_concurrency();
3231
int drogon_thread_num = std::max(thread_num, logical_cores);
3332
#ifdef CORTEX_CPP_VERSION
@@ -40,10 +39,6 @@ void start(const int port = 3929) {
4039
LOG_INFO << "Please load your model";
4140
drogon::app().addListener(host, port);
4241
drogon::app().setThreadNum(drogon_thread_num);
43-
if (!uploads_folder_path.empty()) {
44-
LOG_INFO << "Drogon uploads folder is at: " << uploads_folder_path;
45-
drogon::app().setUploadPath(uploads_folder_path);
46-
}
4742
LOG_INFO << "Number of thread is:" << drogon::app().getThreadNum();
4843

4944
drogon::app().run();

cortex-cpp/controllers/server.cc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ constexpr static auto kTensorrtLlmEngine = "cortex.tensorrt-llm";
2020
} // namespace
2121

2222
server::server() {
23-
2423
// Some default values for now below
2524
// log_disable(); // Disable the log to file feature, reduce bloat for
2625
// target
@@ -297,7 +296,7 @@ void server::LoadModel(const HttpRequestPtr& req,
297296
get_engine_path(engine_type);
298297
#if defined(WIN32)
299298
auto ws = std::wstring(abs_path.begin(), abs_path.end());
300-
if(AddDllDirectory(ws.c_str()) == 0) {
299+
if (AddDllDirectory(ws.c_str()) == 0) {
301300
LOG_WARN << "Could not add dll directory: " << abs_path;
302301
}
303302
#endif
@@ -335,6 +334,36 @@ void server::LoadModel(const HttpRequestPtr& req,
335334
LOG_TRACE << "Done load model";
336335
}
337336

337+
void server::UnloadEngine(
338+
const HttpRequestPtr& req,
339+
std::function<void(const HttpResponsePtr&)>&& callback) {
340+
if (!HasFieldInReq(req, callback, "engine")) {
341+
return;
342+
}
343+
344+
auto engine_type =
345+
(*(req->getJsonObject())).get("engine", cur_engine_type_).asString();
346+
if (!IsEngineLoaded(engine_type)) {
347+
Json::Value res;
348+
res["message"] = "Engine is not loaded yet";
349+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(res);
350+
resp->setStatusCode(k409Conflict);
351+
callback(resp);
352+
LOG_WARN << "Engine is not loaded yet";
353+
return;
354+
}
355+
356+
EngineI* e = std::get<EngineI*>(engines_[engine_type].engine);
357+
delete e;
358+
engines_.erase(engine_type);
359+
LOG_INFO << "Unloaded engine " + engine_type;
360+
Json::Value res;
361+
res["message"] = "Unloaded engine " + engine_type;
362+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(res);
363+
resp->setStatusCode(k200OK);
364+
callback(resp);
365+
}
366+
338367
void server::ProcessStreamRes(std::function<void(const HttpResponsePtr&)> cb,
339368
std::shared_ptr<SyncQueue> q) {
340369
auto err_or_done = std::make_shared<std::atomic_bool>(false);

cortex-cpp/controllers/server.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class server : public drogon::HttpController<server>,
6666
// ADD_METHOD_TO(server::handlePrelight, "/v1/embeddings", Options);
6767

6868
// PATH_ADD("/llama/chat_completion", Post);
69+
METHOD_ADD(server::UnloadEngine, "unloadengine", Post);
70+
6971
METHOD_LIST_END
7072
void ChatCompletion(
7173
const HttpRequestPtr& req,
@@ -91,6 +93,8 @@ class server : public drogon::HttpController<server>,
9193
void FineTuning(
9294
const HttpRequestPtr& req,
9395
std::function<void(const HttpResponsePtr&)>&& callback) override;
96+
void UnloadEngine(const HttpRequestPtr& req,
97+
std::function<void(const HttpResponsePtr&)>&& callback);
9498

9599
private:
96100
void ProcessStreamRes(std::function<void(const HttpResponsePtr&)> cb,

cortex-cpp/engines/cortex.llamacpp/engine.cmake

Lines changed: 0 additions & 92 deletions
This file was deleted.

cortex-cpp/main.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ int main(int argc, char* argv[]) {
4444
int thread_num = 1;
4545
std::string host = "127.0.0.1";
4646
int port = 3928;
47-
std::string uploads_folder_path;
4847

4948
// Number of cortex-cpp threads
5049
if (argc > 1) {
@@ -61,11 +60,6 @@ int main(int argc, char* argv[]) {
6160
port = std::atoi(argv[3]); // Convert string argument to int
6261
}
6362

64-
// Uploads folder path
65-
if (argc > 4) {
66-
uploads_folder_path = argv[4];
67-
}
68-
6963
int logical_cores = std::thread::hardware_concurrency();
7064
int drogon_thread_num = std::max(thread_num, logical_cores);
7165
// cortex_utils::nitro_logo();
@@ -79,10 +73,6 @@ int main(int argc, char* argv[]) {
7973
LOG_INFO << "Please load your model";
8074
drogon::app().addListener(host, port);
8175
drogon::app().setThreadNum(drogon_thread_num);
82-
if (!uploads_folder_path.empty()) {
83-
LOG_INFO << "Drogon uploads folder is at: " << uploads_folder_path;
84-
drogon::app().setUploadPath(uploads_folder_path);
85-
}
8676
LOG_INFO << "Number of thread is:" << drogon::app().getThreadNum();
8777

8878
drogon::app().run();

cortex-cpp/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"url": "git+https://github.com/janhq/cortex.git"
1010
},
1111
"scripts": {
12-
"install": "prebuild-install --runtime napi --backend cmake-js --config Release || cmake-js rebuild --config Release",
13-
"build": "cmake-js configure --config Release && cmake-js build --config Release",
14-
"rebuild": "cmake-js rebuild --config Release",
15-
"prebuild": "prebuild --runtime napi --backend cmake-js --all --strip --verbose --config Release --include-regex \"\\.(node|exp|lib|so)$\"",
12+
"install": "prebuild-install --runtime napi --backend cmake-js --config Release || yarn rebuild",
13+
"build-deps": "cmake-js configure --directory ./cortex-cpp-deps --out ./build-deps/cortex-cpp-deps --config Release && cmake-js build --directory ./cortex-cpp-deps --out ./build-deps/cortex-cpp-deps --config Release",
14+
"build": "yarn build-deps && cmake-js configure --config Release && cmake-js build --config Release",
15+
"rebuild": "yarn build-deps && cmake-js rebuild --config Release",
16+
"prebuild": "yarn build-deps && prebuild --runtime napi --backend cmake-js --all --strip --verbose --config Release --include-regex \"\\.(node|exp|lib|so)$\"",
1617
"upload": "prebuild --runtime napi --backend cmake-js --upload ${GITHUB_TOKEN}"
1718
},
1819
"author": "Jan <service@jan.ai>",
@@ -35,7 +36,6 @@
3536
]
3637
},
3738
"files": [
38-
"binding/*.js",
39-
"binding/*.d.ts"
39+
"**"
4040
]
4141
}

cortex-js/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ AZURE_TENANT_ID ?= xxxx
55
AZURE_CLIENT_SECRET ?= xxxx
66
AZURE_CERT_NAME ?= xxxx
77
DEVELOPER_ID ?= xxxx
8-
CORTEX_EXE_IN ?= "dist/cortexso-win.exe"
8+
CORTEX_EXE_IN ?= "dist/cortexso.exe"
99
CORTEX_EXE_OUT ?= "cortex.exe"
1010
CORTEX_VERSION ?= "0.0.0.1"
1111

1212
update-app-info:
1313
ifeq ($(OS),Windows_NT)
1414
@powershell -Command 'npx resedit --in $(CORTEX_EXE_IN) --out $(CORTEX_EXE_OUT) --icon "1,cortex.ico" --no-grow --company-name "Homebrew Computer Pte Ltd" --file-description "cortex cli" --file-version "$(CORTEX_VERSION)" --internal-name "cortex" --product-name "cortex" --product-version "$(CORTEX_VERSION)"'
1515
else ifeq ($(shell uname -s),Linux)
16-
@cp ./dist/cortexso-linux ./cortex
16+
@cp ./dist/cortexso ./cortex
1717
endif
1818

1919
codesign-binary:

cortex-js/installer.iss

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,50 @@ Name: "quicklaunchicon"; Description: "Create a &Quick Launch icon"; GroupDescri
3737
[Icons]
3838
Name: "{commondesktop}\Cortexso"; Filename: "{app}\cortex.exe"; Tasks: desktopicon
3939
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\Cortexso"; Filename: "{app}\cortex.exe"; Tasks: quicklaunchicon
40+
41+
; Define the uninstall run section to execute commands before uninstallation
42+
[UninstallRun]
43+
Filename: "{app}\cortex.exe"; Parameters: "stop"; StatusMsg: "Stopping Cortexso service..."; Flags: runhidden
44+
45+
; Use Pascal scripting to delete the directory for all users
46+
[Code]
47+
function GetUsersFolder: String;
48+
var
49+
WinDir: String;
50+
begin
51+
WinDir := ExpandConstant('{win}');
52+
Result := Copy(WinDir, 1, Pos('\Windows', WinDir) - 1) + '\Users';
53+
end;
54+
55+
procedure DeleteUserCortexFolder;
56+
var
57+
UsersFolder: String;
58+
FindRec: TFindRec;
59+
begin
60+
UsersFolder := GetUsersFolder;
61+
if FindFirst(UsersFolder + '\*', FindRec) then
62+
begin
63+
try
64+
repeat
65+
if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and
66+
(FindRec.Name <> '.') and (FindRec.Name <> '..') then
67+
begin
68+
if DirExists(UsersFolder + '\' + FindRec.Name + '\cortex') then
69+
begin
70+
DelTree(UsersFolder + '\' + FindRec.Name + '\cortex', True, True, True);
71+
end;
72+
end;
73+
until not FindNext(FindRec);
74+
finally
75+
FindClose(FindRec);
76+
end;
77+
end;
78+
end;
79+
80+
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
81+
begin
82+
if CurUninstallStep = usPostUninstall then
83+
begin
84+
DeleteUserCortexFolder;
85+
end;
86+
end;

0 commit comments

Comments
 (0)