-
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
17 changed files
with
372 additions
and
212 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,25 +45,29 @@ jobs: | |
runs-on: "ubuntu-20-04" | ||
cmake-flags: "" | ||
build-deps-cmake-flags: "" | ||
ccache-dir: '' | ||
arch: "x64" | ||
platform: "linux" | ||
- os: "mac" | ||
name: "amd64" | ||
runs-on: "macos-13" | ||
cmake-flags: "" | ||
build-deps-cmake-flags: "" | ||
ccache-dir: '' | ||
arch: "x64" | ||
platform: "darwin" | ||
- os: "mac" | ||
name: "arm64" | ||
runs-on: "macos-latest" | ||
cmake-flags: "-DMAC_ARM64=ON" | ||
build-deps-cmake-flags: "" | ||
ccache-dir: '' | ||
arch: "arm64" | ||
platform: "darwin" | ||
- os: "windows" | ||
name: "amd64" | ||
runs-on: "windows-cuda-12-0" | ||
cmake-flags: "-DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja" | ||
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja" | ||
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache' | ||
arch: "x64" | ||
platform: "win32" | ||
|
||
steps: | ||
- name: Clone | ||
|
@@ -77,6 +81,11 @@ jobs: | |
with: | ||
dotnet-version: "8.0.x" | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "20.x" | ||
registry-url: "https://registry.npmjs.org" | ||
|
||
- name: Install choco on Windows | ||
if: runner.os == 'Windows' | ||
run: | | ||
|
@@ -116,7 +125,7 @@ jobs: | |
run: | | ||
cd cortex-cpp | ||
make pre-package | ||
- name: Code Signing macOS | ||
if: runner.os == 'macOS' | ||
run: | | ||
|
@@ -163,6 +172,50 @@ jobs: | |
AWS_SECRET_ACCESS_KEY: "${{ secrets.MINIO_SECRET_ACCESS_KEY }}" | ||
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}" | ||
|
||
## cortex-cpp node binding | ||
|
||
# update version in package.json | ||
- name: Install jq | ||
uses: dcarbone/[email protected] | ||
|
||
- name: "Update version by tag" | ||
working-directory: cortex-cpp | ||
run: | | ||
echo "Version: ${{ needs.create-draft-release.outputs.version }}" | ||
# Update the version in package.json | ||
jq --arg version "${{ needs.create-draft-release.outputs.version }}" '.version = $version' package.json > package-tmp.json | ||
rm package.json | ||
mv package-tmp.json package.json | ||
# build prebuilds | ||
- name: Build Prebuilds | ||
working-directory: cortex-cpp | ||
run: | | ||
npm install -g yarn | ||
yarn && yarn prebuild | ||
# upload prebuilds | ||
- name: Upload Prebuilds Darwin | ||
uses: actions/[email protected] | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ needs.create-draft-release.outputs.upload_url }} | ||
asset_path: ./cortex-cpp/prebuilds/cortex-cpp-v${{ needs.create-draft-release.outputs.version }}-napi-v8-${{matrix.platform}}-${{ matrix.arch }}.tar.gz | ||
asset_name: cortex-cpp-v${{ needs.create-draft-release.outputs.version }}-napi-v8-${{matrix.platform}}-${{ matrix.arch }}.tar.gz | ||
asset_content_type: application/gzip | ||
|
||
# Setup .npmrc file to publish to npm - upload only once | ||
- run: npm publish --access public | ||
continue-on-error: true | ||
if: runner.os == 'linux' | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
working-directory: ./cortex-cpp | ||
|
||
## cortex-cpp node binding | ||
|
||
build-cortex-single-binary: | ||
runs-on: ${{ matrix.runs-on }} | ||
needs: [create-draft-release] | ||
|
@@ -229,7 +282,7 @@ jobs: | |
with: | ||
python-version: "3.10" | ||
|
||
- run: pip3 install --upgrade setuptools | ||
- run: pip3 install --upgrade setuptools | ||
if: runner.os == 'macOS' | ||
|
||
- run: yarn install && yarn build:binary | ||
|
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,88 @@ | ||
#include <napi.h> | ||
|
||
#include <drogon/HttpAppFramework.h> | ||
#include <drogon/drogon.h> | ||
#include <stdlib.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 | ||
|
||
static Napi::Env* s_env = nullptr; | ||
|
||
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); | ||
#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(); | ||
} | ||
|
||
void exitCallback() { | ||
Napi::TypeError::New(*s_env, "Process Exited!").ThrowAsJavaScriptException(); | ||
} | ||
|
||
Napi::Value Start(const Napi::CallbackInfo& info) { | ||
Napi::Env env = info.Env(); | ||
|
||
s_env = &env; | ||
|
||
// Register exitCallback with atexit | ||
std::atexit(exitCallback); | ||
|
||
start(); | ||
return env.Undefined(); | ||
} | ||
|
||
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 @@ | ||
// Type definitions for cortex-cpp node binding | ||
|
||
/// <reference types="node" /> | ||
declare module "cortex-cpp" { | ||
export function start(); | ||
export function 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,3 @@ | ||
const addon = require("./../build/Release/cortex-cpp.node"); | ||
|
||
module.exports = addon; |
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
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,41 @@ | ||
{ | ||
"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": "./binding/index.js", | ||
"types": "./binding/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/janhq/cortex.git" | ||
}, | ||
"scripts": { | ||
"install": "prebuild-install --runtime napi --backend cmake-js --config Release || cmake-js rebuild --config Release", | ||
"build": "cmake-js configure --config Release && cmake-js build --config Release", | ||
"rebuild": "cmake-js rebuild --config Release", | ||
"prebuild": "prebuild --runtime napi --backend cmake-js --all --strip --verbose --config Release", | ||
"upload": "prebuild --runtime napi --backend cmake-js --upload ${GITHUB_TOKEN}" | ||
}, | ||
"author": "Jan <[email protected]>", | ||
"license": "Apache-2.0", | ||
"gypfile": true, | ||
"dependencies": { | ||
"bindings": "^1.5.0", | ||
"cmake-js": "^7.3.0", | ||
"node-addon-api": "^7.0.0", | ||
"prebuild": "^13.0.1", | ||
"prebuild-install": "^7.1.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.9", | ||
"typescript": "^5.5.3" | ||
}, | ||
"binary": { | ||
"napi_versions": [ | ||
8 | ||
] | ||
}, | ||
"files": [ | ||
"binding/*.js", | ||
"binding/*.d.ts" | ||
] | ||
} |
Oops, something went wrong.