Skip to content

Commit 95f4645

Browse files
authored
feat: parallel function calling (#225)
* feat: parallel function calling * feat: preload prompt * feat: prompt completion engine * feat: chat wrapper based system message support * feat: add prompt completion to the Electron example * feat: model compatibility warnings * feat: Functionary `v2.llama3` support * feat: parallel function calling with plain Llama 3 Instruct * feat: improve function calling support for default chat wrapper * feat: parallel model downloads * feat: add the electron example to releases * feat: improve the electron example * feat: `customStopTriggers` for `LlamaCompletion` * fix: improve CUDA detection on Windows * fix: performance improvements * refactor: make `functionCallMessageTemplate` an object * chore: adapt to `llama.cpp` breaking changes
1 parent 6619b28 commit 95f4645

File tree

114 files changed

+7044
-2432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+7044
-2432
lines changed

.config/typedoc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
"enumMembersFormat": "table",
2525
"typeDeclarationFormat": "list",
2626
"sort": ["source-order"],
27-
"docsRoot": "../docs"
27+
"docsRoot": "../docs",
28+
"intentionallyNotExported": ["MergeOptionalUnionTypes", "GbnfJsonSchemaToTSType", "_LlamaText"]
2829
}

.github/workflows/build.yml

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
generators: "Ninja"
6868
artifact: "linux"
6969
- name: "macOS Clang"
70-
os: macos-12
70+
os: macos-13
7171
cc: "clang"
7272
cxx: "clang++"
7373
generators: "Xcode"
@@ -110,18 +110,18 @@ jobs:
110110
111111
- name: Install Cuda on Windows
112112
if: startsWith(matrix.config.os, 'windows')
113-
uses: Jimver/[email protected].11
113+
uses: Jimver/[email protected].15
114114
with:
115-
cuda: '12.2.0'
115+
cuda: '12.4.1'
116116
method: 'network'
117117
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
118118
use-local-cache: false
119119

120120
- name: Install Cuda on Ubuntu
121121
if: startsWith(matrix.config.name, 'Ubuntu GCC')
122-
uses: Jimver/[email protected].11
122+
uses: Jimver/[email protected].15
123123
with:
124-
cuda: '12.2.0'
124+
cuda: '12.4.1'
125125
method: 'network'
126126

127127
- name: Install Vulkan SDK on Windows
@@ -198,7 +198,7 @@ jobs:
198198
async function buildBinary(arch, flags = [], nodeTarget = nodeVersion) {
199199
console.log(`Building ${arch} for node ${nodeTarget} with flags`, flags);
200200
201-
await $`node ./dist/cli/cli.js build --noUsageExample --arch ${arch} --nodeTarget ${nodeVersion} ${flags}`;
201+
await $`node ./dist/cli/cli.js build --ciMode --noUsageExample --arch ${arch} --nodeTarget ${nodeVersion} ${flags}`;
202202
}
203203
204204
// build binaries
@@ -343,6 +343,8 @@ jobs:
343343
needs:
344344
- build
345345
- build-binaries
346+
outputs:
347+
package-version: ${{ steps.set-package-version.outputs.package-version }}
346348
steps:
347349
- uses: actions/checkout@v4
348350
with:
@@ -391,6 +393,12 @@ jobs:
391393
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
392394
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
393395
fi
396+
- name: Set package version to GITHUB_OUTPUT
397+
id: set-package-version
398+
run: |
399+
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
400+
echo "package-version=$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
401+
fi
394402
- name: Prepare `create-node-llama-cpp` module
395403
if: steps.set-npm-url.outputs.npm-url != ''
396404
run: |
@@ -437,3 +445,56 @@ jobs:
437445
uses: actions/deploy-pages@v4
438446
with:
439447
artifact_name: pages-docs
448+
449+
build-electron-example:
450+
name: Build & release Electron app example - ${{ matrix.config.name }}
451+
needs:
452+
- release
453+
if: needs.release.outputs.package-version != ''
454+
runs-on: ${{ matrix.config.os }}
455+
permissions:
456+
contents: write
457+
strategy:
458+
fail-fast: false
459+
matrix:
460+
config:
461+
- name: "Windows"
462+
os: windows-2022
463+
- name: "Ubuntu"
464+
os: ubuntu-22.04
465+
- name: "macOS"
466+
os: macos-13
467+
468+
steps:
469+
- uses: actions/checkout@v4
470+
- uses: actions/setup-node@v4
471+
with:
472+
node-version: "20"
473+
474+
- name: Install modules
475+
run: npm ci
476+
477+
- name: Create Electron app project
478+
env:
479+
DEPLOYED_PACKAGE_VERSION: ${{ needs.release.outputs.package-version }}
480+
run: |
481+
npx --no vite-node ./scripts/scaffoldElectronExampleForCiBuild.ts --packageVersion "$DEPLOYED_PACKAGE_VERSION" --packageFolderPath ./electron-app-example
482+
cd electron-app-example
483+
npm install
484+
485+
- name: Build electron app
486+
id: build
487+
shell: bash
488+
timeout-minutes: 480
489+
run: |
490+
cd electron-app-example
491+
npm run build
492+
ls ./release
493+
494+
- name: Add builds to current release
495+
uses: svenstaro/upload-release-action@v2
496+
with:
497+
file: "electron-app-example/release/*.{dmg,zip,exe,appx,AppImage,snap,deb,tar.gz}"
498+
file_glob: true
499+
tag: ${{ needs.release.outputs.package-version }}
500+
make_latest: false

llama/addon.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ static Napi::Value getNapiToken(const Napi::CallbackInfo& info, llama_model* mod
222222
return Napi::Number::From(info.Env(), -1);
223223
}
224224

225-
auto tokenType = llama_token_get_type(model, token);
225+
auto tokenAttributes = llama_token_get_attr(model, token);
226226

227-
if (tokenType == LLAMA_TOKEN_TYPE_UNDEFINED || tokenType == LLAMA_TOKEN_TYPE_UNKNOWN) {
227+
if (tokenAttributes & LLAMA_TOKEN_ATTR_UNDEFINED || tokenAttributes & LLAMA_TOKEN_ATTR_UNKNOWN) {
228228
return Napi::Number::From(info.Env(), -1);
229229
}
230230

@@ -236,9 +236,9 @@ static Napi::Value getNapiControlToken(const Napi::CallbackInfo& info, llama_mod
236236
return Napi::Number::From(info.Env(), -1);
237237
}
238238

239-
auto tokenType = llama_token_get_type(model, token);
239+
auto tokenAttributes = llama_token_get_attr(model, token);
240240

241-
if (tokenType != LLAMA_TOKEN_TYPE_CONTROL && tokenType != LLAMA_TOKEN_TYPE_USER_DEFINED) {
241+
if (!(tokenAttributes & LLAMA_TOKEN_ATTR_CONTROL) && !(tokenAttributes & LLAMA_TOKEN_ATTR_UNDEFINED)) {
242242
return Napi::Number::From(info.Env(), -1);
243243
}
244244

@@ -535,20 +535,20 @@ class AddonModel : public Napi::ObjectWrap<AddonModel> {
535535
return Napi::String::New(info.Env(), ss.str());
536536
}
537537

538-
Napi::Value GetTokenType(const Napi::CallbackInfo& info) {
538+
Napi::Value GetTokenAttributes(const Napi::CallbackInfo& info) {
539539
if (disposed) {
540540
Napi::Error::New(info.Env(), "Model is disposed").ThrowAsJavaScriptException();
541541
return info.Env().Undefined();
542542
}
543543

544544
if (info[0].IsNumber() == false) {
545-
return Napi::Number::From(info.Env(), int32_t(LLAMA_TOKEN_TYPE_UNDEFINED));
545+
return Napi::Number::From(info.Env(), int32_t(LLAMA_TOKEN_ATTR_UNDEFINED));
546546
}
547547

548548
int token = info[0].As<Napi::Number>().Int32Value();
549-
auto tokenType = llama_token_get_type(model, token);
549+
auto tokenAttributes = llama_token_get_attr(model, token);
550550

551-
return Napi::Number::From(info.Env(), int32_t(tokenType));
551+
return Napi::Number::From(info.Env(), int32_t(tokenAttributes));
552552
}
553553
Napi::Value IsEogToken(const Napi::CallbackInfo& info) {
554554
if (disposed) {
@@ -611,7 +611,7 @@ class AddonModel : public Napi::ObjectWrap<AddonModel> {
611611
InstanceMethod("suffixToken", &AddonModel::SuffixToken),
612612
InstanceMethod("eotToken", &AddonModel::EotToken),
613613
InstanceMethod("getTokenString", &AddonModel::GetTokenString),
614-
InstanceMethod("getTokenType", &AddonModel::GetTokenType),
614+
InstanceMethod("getTokenAttributes", &AddonModel::GetTokenAttributes),
615615
InstanceMethod("isEogToken", &AddonModel::IsEogToken),
616616
InstanceMethod("getVocabularyType", &AddonModel::GetVocabularyType),
617617
InstanceMethod("shouldPrependBosToken", &AddonModel::ShouldPrependBosToken),

0 commit comments

Comments
 (0)