-
Notifications
You must be signed in to change notification settings - Fork 90
Initial project setup for llamacpp bindings #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nnance
wants to merge
20
commits into
vercel:main
Choose a base branch
from
nnance:llamacpp-bindings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+954
−54
Draft
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
77dd5c9
initial project setup
nnance 968908f
restructure folders for llamacpp dependencies
nnance d9c17d7
integrate llama.cpp with cmake-js
nnance 5ef0a08
convert tests to typescript
nnance 9b8c74a
initial provider implementation
nnance 6f8ae9b
Merge branch 'main' into llamacpp-bindings
nnance 908cbc5
move provider implementation into package
nnance 4d5e00e
use LlamaCppCompletionPrompt / Settings from modelfusion for consistency
nnance 124e041
loading native node module with es6 enabled
nnance 3f42f2f
now using vitest for automated tests
nnance 791aea1
put helper scripts into the bin
nnance 77c7125
revert build ignore
nnance d20041a
Merge remote-tracking branch 'upstream/main' into llamacpp-bindings
nnance a0702ab
fix ci workflow
nnance 1d22143
Merge remote-tracking branch 'upstream/main' into llamacpp-bindings
nnance 928fa8d
update lock
nnance 3a29f23
use LLamaCppCompletionModel as a base class
nnance a8ffbec
Merge remote-tracking branch 'upstream/main' into llamacpp-bindings
nnance e309265
initial shell of completion model
nnance 05096c8
Merge remote-tracking branch 'upstream/main' into llamacpp-bindings
nnance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
21 changes: 21 additions & 0 deletions
21
packages/@modelfusion-llamacpp-bindings/.vscode/c_cpp_properties.json
This file contains hidden or 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,21 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Mac", | ||
"includePath": [ | ||
"${workspaceFolder}/**", | ||
"${workspaceFolder}/node_modules/node-addon-api", | ||
"/usr/local/include/node" | ||
], | ||
"defines": [], | ||
"macFrameworkPath": [ | ||
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" | ||
], | ||
"compilerPath": "/usr/bin/clang", | ||
"cStandard": "c17", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "macos-clang-arm64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains hidden or 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,46 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
project("llamacpp-bindings-native" C CXX) | ||
|
||
if (MSVC) | ||
# add_compile_options(/EHsc) | ||
else() | ||
add_compile_options(-fexceptions) | ||
endif() | ||
|
||
add_definitions(-DNAPI_VERSION=7) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
execute_process(COMMAND node -p "require('node-addon-api').include.slice(1,-1)" | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
OUTPUT_VARIABLE NODE_ADDON_API_DIR | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
|
||
include_directories(${NODE_ADDON_API_DIR} ${CMAKE_JS_INC}) | ||
|
||
if(EXISTS ${CMAKE_SOURCE_DIR}/lib/llamacpp) | ||
add_subdirectory(${CMAKE_SOURCE_DIR}/lib/llamacpp) | ||
include_directories(${CMAKE_SOURCE_DIR}/lib/llamacpp) | ||
include_directories(${CMAKE_SOURCE_DIR}/lib/llamacpp/common) | ||
else() | ||
message(FATAL_ERROR "Directory 'lib/llamacpp' does not exist. Run ./update_submodules.sh") | ||
endif() | ||
|
||
file(GLOB SOURCE_FILES "src/llamacpp_bindings.cc") | ||
|
||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC}) | ||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node") | ||
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB}) | ||
target_link_libraries(${PROJECT_NAME} "llama") | ||
target_link_libraries(${PROJECT_NAME} "common") | ||
|
||
# copy ggml-metal.metal to release folder | ||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy | ||
${CMAKE_SOURCE_DIR}/lib/llamacpp/ggml-metal.metal | ||
${CMAKE_CURRENT_BINARY_DIR}/Release/ggml-metal.metal) | ||
|
||
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) | ||
# Generate node.lib | ||
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) | ||
endif() |
19 changes: 19 additions & 0 deletions
19
packages/@modelfusion-llamacpp-bindings/bin/update_submodules.sh
This file contains hidden or 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,19 @@ | ||
#!/bin/bash | ||
|
||
# Define the repository URL | ||
REPO_URL="https://github.com/ggerganov/llama.cpp.git" | ||
|
||
# Define the directory where the repository will be cloned | ||
DIR="lib/llamacpp" | ||
|
||
# If the directory already exists, pull the latest changes | ||
if [ -d "$DIR" ]; then | ||
echo "Directory $DIR exists." | ||
echo "Pulling latest changes..." | ||
cd "$DIR" && git pull origin master | ||
else | ||
# If the directory does not exist, clone the repository | ||
echo "Directory $DIR does not exist." | ||
echo "Cloning repository..." | ||
git clone "$REPO_URL" "$DIR" | ||
fi |
This file contains hidden or 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,16 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "llamacpp-bindings-native", | ||
"type": "none", | ||
"actions": [ | ||
{ | ||
"action_name": "build", | ||
"inputs": ["<(module_root_dir)/CMakeLists.txt"], | ||
"outputs": ["<(module_root_dir)/build"], | ||
"action": ["cmake-js"] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or 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,45 @@ | ||
{ | ||
"dependencies": { | ||
"node-addon-api": "^7.0.0" | ||
}, | ||
"scripts": { | ||
"setup": "./bin/update_submodules.sh", | ||
"build": "node-gyp rebuild && tsc", | ||
"clean": "node-gyp clean && tsc --build --clean", | ||
"pretest": "tsc", | ||
"test": "vitest --run src" | ||
}, | ||
"gypfile": true, | ||
"name": "@modelfusion/llamacpp-bindings", | ||
"version": "0.0.1", | ||
"description": "llama.cpp bindings for ModelFusion", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/lgrammel/modelfusion.git" | ||
}, | ||
"type": "module", | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"main": "./dist/index.js", | ||
"keywords": [ | ||
"modelfusion", | ||
"llamacpp", | ||
"llama" | ||
], | ||
"author": "Nick Nance", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lgrammel/modelfusion/issues" | ||
}, | ||
"homepage": "https://github.com/lgrammel/modelfusion#readme", | ||
"devDependencies": { | ||
"@types/node": "^20.11.3", | ||
"cmake-js": "^7.3.0", | ||
"typescript": "^5.3.3", | ||
"modelfusion": "0.131.0" | ||
}, | ||
"peerDependencies": { | ||
"modelfusion": ">=0.131.0" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.