-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include <napi.h> | ||
|
||
#include <drogon/HttpAppFramework.h> | ||
#include <drogon/drogon.h> | ||
#include <climits> // for PATH_MAX | ||
#include <iostream> | ||
#include "cortex-common/cortexpythoni.h" | ||
#include "utils/cortex_utils.h" | ||
#include "utils/dylib.h" | ||
|
||
#if defined(__APPLE__) && defined(__MACH__) | ||
#include <libgen.h> // for dirname() | ||
#include <mach-o/dyld.h> | ||
#elif defined(__linux__) | ||
#include <libgen.h> // for dirname() | ||
#include <unistd.h> // for readlink() | ||
#elif defined(_WIN32) | ||
#include <windows.h> | ||
#undef max | ||
#else | ||
#error "Unsupported platform!" | ||
#endif | ||
|
||
void start() { | ||
int thread_num = 1; | ||
std::string host = "127.0.0.1"; | ||
int port = 3929; | ||
std::string uploads_folder_path; | ||
|
||
int logical_cores = std::thread::hardware_concurrency(); | ||
int drogon_thread_num = std::max(thread_num, logical_cores); | ||
// cortex_utils::nitro_logo(); | ||
#ifdef CORTEX_CPP_VERSION | ||
LOG_INFO << "cortex-cpp version: " << CORTEX_CPP_VERSION; | ||
#else | ||
LOG_INFO << "cortex-cpp version: undefined"; | ||
#endif | ||
#ifdef CORTEX_LLAMACPP_VERSION | ||
LOG_INFO << "cortex.llamacpp version: " << CORTEX_LLAMACPP_VERSION; | ||
#endif | ||
|
||
LOG_INFO << "Server started, listening at: " << host << ":" << port; | ||
LOG_INFO << "Please load your model"; | ||
drogon::app().addListener(host, port); | ||
drogon::app().setThreadNum(drogon_thread_num); | ||
if (!uploads_folder_path.empty()) { | ||
LOG_INFO << "Drogon uploads folder is at: " << uploads_folder_path; | ||
drogon::app().setUploadPath(uploads_folder_path); | ||
} | ||
LOG_INFO << "Number of thread is:" << drogon::app().getThreadNum(); | ||
|
||
drogon::app().run(); | ||
} | ||
|
||
void stop() { | ||
drogon::app().quit(); | ||
} | ||
|
||
Napi::Value Start(const Napi::CallbackInfo &info) | ||
{ | ||
Napi::Env env = info.Env(); | ||
start(); | ||
return Napi::String::New(env, "Server started successfully"); | ||
} | ||
|
||
Napi::Value Stop(const Napi::CallbackInfo &info) | ||
{ | ||
Napi::Env env = info.Env(); | ||
stop(); | ||
return Napi::String::New(env, "Server stopped successfully"); | ||
} | ||
|
||
Napi::Object Init(Napi::Env env, Napi::Object exports) | ||
{ | ||
exports.Set(Napi::String::New(env, "start"), | ||
Napi::Function::New(env, Start)); | ||
exports.Set(Napi::String::New(env, "stop"), | ||
Napi::Function::New(env, Start)); | ||
return exports; | ||
} | ||
|
||
NODE_API_MODULE(cortex-cpp, Init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const addon = require("./build/Release/cortex-cpp.node"); | ||
|
||
console.log(addon); | ||
|
||
console.log(addon.start()); | ||
|
||
console.log(addon.stop()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "cortex-cpp", | ||
"version": "0.0.11", | ||
"description": "Cortex-cpp is a streamlined, stateless C++ server engineered to be fully compatible with OpenAI's API, particularly its stateless functionalities", | ||
"main": "./index.js", | ||
"types": "./index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/janhq/cortex.git" | ||
}, | ||
"scripts": { | ||
"install": "prebuild-install --runtime napi --backend cmake-js || cmake-js rebuild", | ||
"build": "cmake-js configure && cmake-js build", | ||
"rebuild": "cmake-js rebuild", | ||
"prebuild": "prebuild --runtime napi --backend cmake-js --all --strip --verbose", | ||
"upload": "prebuild --runtime napi --backend cmake-js --upload ${GITHUB_TOKEN}" | ||
}, | ||
"author": "louis", | ||
"license": "Apache-2.0", | ||
"gypfile": true, | ||
"dependencies": { | ||
"bindings": "^1.5.0", | ||
"cmake-js": "^7.3.0", | ||
"node-addon-api": "^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.9", | ||
"typescript": "^5.5.3" | ||
}, | ||
"binary": { | ||
"napi_versions": [ | ||
8 | ||
] | ||
}, | ||
"files": [ | ||
"binding.gyp", | ||
"deps/", | ||
"*.js", | ||
"*.d.ts", | ||
"src/", | ||
"prebuilds/" | ||
] | ||
} |