Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
developer239 committed Jul 27, 2024
0 parents commit 4ca9e93
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Release

on:
push:
branches:
- master

jobs:
release:
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
submodules: 'recursive'
token: ${{ secrets.GH_TOKEN }}

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 18

- name: Install dependencies
run: yarn install

- name: Semantic release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.idea/

/cpp/.idea/
/cpp/build/
/cpp/cmake-build-debug/

/node_modules/
20 changes: 20 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
[
"@semantic-release/git",
{
"assets": [
"package.json",
"CHANGELOG.md"
]
}
]
],
"branches": [
"master"
]
}
45 changes: 45 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.24)

project(llamacpp_node_bindings)

set(CMAKE_CXX_STANDARD 14)

# Use cmake-js provided node-addon-api and Node.js include directories
include_directories(${CMAKE_JS_INC})

# Define the Node.js addon target
add_library(${PROJECT_NAME} SHARED
src/main.cpp
src/LlamaCPPBinding.h
src/LlamaCPPBinding.cpp
${CMAKE_JS_SRC}
)

# Set target output name to 'addon.node'
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")

# Add RobotCPP submodule library
add_subdirectory(${CMAKE_SOURCE_DIR}/externals/llama-cpp)

# Link the RobotCPP library and cmake-js provided Node.js runtime libraries
target_link_libraries(${PROJECT_NAME} PRIVATE
RobotCPP
${CMAKE_JS_LIB}
)

# Set the output directory to 'build/Release' for compatibility with Node.js
set_target_properties(${PROJECT_NAME} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Release
)

# Include Node-API wrappers
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
string(REGEX REPLACE "[\r\n\"]" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})

target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})

# define NAPI_VERSION
add_definitions(-DNAPI_VERSION=3)
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class LlamaWrapper {
constructor();
initialize(modelPath: string, contextSize?: number): boolean;
runQuery(prompt: string, maxTokens?: number): string;
runQueryStream(prompt: string, maxTokens: number, callback: (response: string) => void): void;
}
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const llama = require('./cpp/build/Release/llamacpp_node_bindings.node');

module.exports = {
LlamaWrapper: llama.LlamaWrapper
};
43 changes: 43 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "llama.cpp-ts",
"version": "0.0.1",
"description": "Node.js bindings for LlamaCPP, a C++ library for running language models.",
"repository": "https://github.com/developer239/llama.cpp-ts",
"main": "index.js",
"typings": "index.d.ts",
"private": false,
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"node-addon-api": "6.1.0",
"cmake-js": "7.2.1"
},
"scripts": {
"install": "cmake-js compile",
"build": "cmake-js compile"
},
"keywords": [
"node",
"language-model",
"c++",
"cpp",
"node-addon-api",
"cmake",
"cmake-js",
"llama",
"llama.cpp",
"3.1"
],
"devDependencies": {
"@semantic-release/changelog": "6.0.3",
"@semantic-release/commit-analyzer": "9.0.2",
"@semantic-release/git": "10.0.1",
"@semantic-release/npm": "10.0.3",
"@semantic-release/release-notes-generator": "10.0.3",
"semantic-release": "21.0.1"
}
}

0 comments on commit 4ca9e93

Please sign in to comment.