Skip to content

Commit 4b3ad61

Browse files
authored
feat: new docs (#309)
* feat: Functionary v3 support * feat: Mistral chat wrapper * feat: move `seed` option to the prompt level * feat: make `LlamaEmbedding` an object * feat: `HF_TOKEN` support for reading GGUF file metadata * feat: `inspect estimate` command * feat(`TemplateChatWrapper`): custom history template for each message role * feat: extract all prebuilt binaries to external modules * feat: more helpful `inspect gpu` command * feat: combine model downloaders * feat: simplify `TokenBias` * feat: simplify compatibility detection * feat: better `threads` default value * feat: improve Llama 3.1 chat template detection * feat: `--gpuLayers max` and `--contextSize max` flag support for `inspect estimate` command * feat: iterate all tokenizer tokens * feat: failed context creation automatic remedy * feat: abort generation in CLI commands * feat(electron example template): update badge, scroll anchoring, table support * refactor: move `download`, `build` and `clear` commands to be subcommands of a `source` command * docs: new docs * fix: adapt to `llama.cpp` sampling refactor * fix: Llama 3.1 chat wrapper standard chat history * fix: Llama 3 Instruct function calling * fix: don't preload prompt in the `chat` command when using `--printTimings` or `--meter` * fix: change `autoDisposeSequence` default to `false` * fix: more stable Jinja template matching * fix: improve performance of parallel evaluation from multiple contexts * build(CI): resolve next version before release, update documentation website without a release * build: only create a GitHub discussion on major or minor releases * chore: update models list * chore: remove unused field from `TokenMeter`
1 parent bf12e9c commit 4b3ad61

File tree

316 files changed

+20136
-4183
lines changed

Some content is hidden

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

316 files changed

+20136
-4183
lines changed

.config/typedoc.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ h6:not(.tsd-anchor-link, .tsd-returns-title) > a:hover:before {
214214
margin-top: 16px;
215215
}
216216

217-
img[src$="assets/logo.roundEdges.png"],
218-
img[src$="assets/logo.png"] {
217+
img[src$="assets/logo.v3.roundEdges.png"],
218+
img[src$="assets/logo.v3.png"] {
219219
box-shadow: 0px 4px 12px 0px rgb(0 0 0 / 16%), 0px 8px 64px 0px rgb(0 0 0 / 24%);
220220
border-radius: 14px;
221221
}

.config/typedoc.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://typedoc.org/schema.json",
3-
"entryPoints": ["../src/index.ts"],
3+
"entryPoints": ["../src/apiDocsIndex.ts"],
44
"out": "../docs/api",
55
"tsconfig": "../tsconfig.json",
66
"customCss": "./typedoc.css",
@@ -11,7 +11,7 @@
1111
"githubPages": true,
1212
"hideGenerator": true,
1313
"jsDocCompatibility": true,
14-
"htmlLang": "en",
14+
"lang": "en",
1515
"plugin": ["typedoc-plugin-markdown", "typedoc-vitepress-theme", "typedoc-plugin-mdn-links"],
1616
"hideBreadcrumbs": true,
1717
"hidePageHeader": true,
@@ -23,7 +23,10 @@
2323
"propertiesFormat": "list",
2424
"enumMembersFormat": "table",
2525
"typeDeclarationFormat": "list",
26+
"classPropertiesFormat": "list",
27+
"interfacePropertiesFormat": "list",
2628
"sort": ["source-order"],
2729
"docsRoot": "../docs",
28-
"intentionallyNotExported": ["MergeOptionalUnionTypes", "GbnfJsonSchemaToTSType", "_LlamaText"]
30+
"intentionallyNotExported": ["MergeOptionalUnionTypes", "GbnfJsonSchemaToTSType", "_LlamaText"],
31+
"useHTMLEncodedBrackets": true
2932
}

.github/ISSUE_TEMPLATE/bug-report.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ body:
3939
Your bug can be investigated much faster if your code can be run without any dependencies other than `node-llama-cpp`.
4040
Issues without reproduction steps or code examples may be closed as not actionable.
4141
Please try to provide a Minimal, Complete, and Verifiable example ([link](http://stackoverflow.com/help/mcve)).
42+
Please include a link to the model file you used if possible.
4243
Also, please enable enable debug logs by using `getLlama({debug: true})` to get more information.
4344
placeholder: >-
4445
Please try to provide a Minimal, Complete, and Verifiable example.

.github/ISSUE_TEMPLATE/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
blank_issues_enabled: false
12
contact_links:
23
- name: 🤔 Questions, General Support, and Help
34
url: https://github.com/withcatai/node-llama-cpp/discussions

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
- [ ] This pull request links relevant issues as `Fixes #0000`
3030
- [ ] There are new or updated unit tests validating the change
3131
- [ ] Documentation has been updated to reflect this change
32-
- [ ] The new commits and pull request title follow conventions explained in [pull request guidelines](https://withcatai.github.io/node-llama-cpp/guide/contributing) (PRs that do not follow this convention will not be merged)
32+
- [ ] The new commits and pull request title follow conventions explained in [pull request guidelines](https://node-llama-cpp.withcat.ai/guide/contributing) (PRs that do not follow this convention will not be merged)

.github/workflows/build.yml

+156-29
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ jobs:
2323
- name: Download latest llama.cpp release
2424
env:
2525
CI: true
26-
run: node ./dist/cli/cli.js download --release b3543 --skipBuild --noBundle --noUsageExample --updateBinariesReleaseMetadataAndSaveGitBundle
26+
run: node ./dist/cli/cli.js source download --release latest --skipBuild --noBundle --noUsageExample --updateBinariesReleaseMetadataAndSaveGitBundle
2727
- name: Upload build artifact
2828
uses: actions/upload-artifact@v4
2929
with:
30+
include-hidden-files: true
3031
name: "build"
3132
path: "dist"
3233
- name: Upload packed templates artifact
3334
uses: actions/upload-artifact@v4
3435
with:
36+
include-hidden-files: true
3537
name: "build-templates"
3638
path: "templates/packed"
3739
- name: Upload llama.cpp artifact
3840
uses: actions/upload-artifact@v4
3941
with:
42+
include-hidden-files: true
4043
name: "llama.cpp"
4144
path: |
4245
llama/binariesGithubRelease.json
@@ -145,7 +148,7 @@ jobs:
145148
- name: Setup & Build
146149
id: build
147150
shell: bash
148-
timeout-minutes: 80
151+
timeout-minutes: 160
149152
env:
150153
ARTIFACT_NAME: ${{ matrix.config.artifact }}
151154
run: |
@@ -193,7 +196,7 @@ jobs:
193196
async function buildBinary(arch, flags = [], nodeTarget = nodeVersion) {
194197
console.log(`Building ${arch} for node ${nodeTarget} with flags`, flags);
195198
196-
await $`node ./dist/cli/cli.js build --ciMode --noUsageExample --arch ${arch} --nodeTarget ${nodeVersion} ${flags}`;
199+
await $`node ./dist/cli/cli.js source build --ciMode --noUsageExample --arch ${arch} --nodeTarget ${nodeVersion} ${flags}`;
197200
}
198201
199202
// build binaries
@@ -229,12 +232,12 @@ jobs:
229232
230233
EOF
231234
232-
- name: Cache UPX
233-
id: cache-upx
234-
uses: actions/cache@v4
235-
with:
236-
path: "upxInstallations/**"
237-
key: cache-upx-${{ runner.os }}-${{ github.workflow }}
235+
# - name: Cache UPX
236+
# id: cache-upx
237+
# uses: actions/cache@v4
238+
# with:
239+
# path: "upxInstallations/**"
240+
# key: cache-upx-${{ runner.os }}-${{ github.workflow }}
238241

239242
# - name: Compress CUDA binary on Windows
240243
# if: matrix.config.name == 'Windows for x64'
@@ -280,9 +283,48 @@ jobs:
280283
- name: Publish artifact
281284
uses: actions/upload-artifact@v4
282285
with:
286+
include-hidden-files: true
283287
name: "bins-${{ matrix.config.artifact }}"
284288
path: "bins/*"
285289

290+
resolve-next-release:
291+
name: Resolve next release
292+
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta')
293+
runs-on: ubuntu-latest
294+
permissions:
295+
pages: read
296+
id-token: write
297+
contents: read
298+
issues: read
299+
pull-requests: read
300+
discussions: read
301+
steps:
302+
- uses: actions/checkout@v4
303+
- uses: actions/setup-node@v4
304+
with:
305+
node-version: "20"
306+
- name: Install modules
307+
run: npm ci
308+
- name: Resolve next release
309+
env:
310+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
311+
run: npx --no vite-node ./scripts/resolveNextReleaseVersion.ts --saveReleaseToFile ./semanticReleaseDryRunReleaseResult.json --saveVersionToFile ./resolvedNextVersion.txt
312+
- name: Save next version output
313+
run: echo "next-version=$(cat ./resolvedNextVersion.txt)" >> $GITHUB_ENV
314+
- name: Update job summary
315+
run: |
316+
if [ "$(cat ./resolvedNextVersion.txt)" == "false" ]; then
317+
echo "Next release version: `N/A`" >> $GITHUB_STEP_SUMMARY
318+
else
319+
echo "Next release version: `$(cat ./resolvedNextVersion.txt)`" >> $GITHUB_STEP_SUMMARY
320+
fi
321+
- name: Upload resolved release artifact
322+
uses: actions/upload-artifact@v4
323+
with:
324+
include-hidden-files: true
325+
name: "resolved-next-release"
326+
path: "./semanticReleaseDryRunReleaseResult.json"
327+
286328
standalone-tests:
287329
name: Standalone tests
288330
runs-on: ubuntu-22.04
@@ -315,7 +357,7 @@ jobs:
315357
run: npm ci
316358

317359
- name: Build binary
318-
run: node ./dist/cli/cli.js build --noUsageExample
360+
run: node ./dist/cli/cli.js source build --noUsageExample
319361

320362
- name: Run standalone tests
321363
run: npm run test:standalone
@@ -354,7 +396,7 @@ jobs:
354396
run: npm ci
355397

356398
- name: Build binary
357-
run: node ./dist/cli/cli.js build --noUsageExample
399+
run: node ./dist/cli/cli.js source build --noUsageExample
358400

359401
- name: Cache models
360402
id: cache-test-models
@@ -371,7 +413,7 @@ jobs:
371413

372414
release:
373415
name: Release
374-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta')
416+
if: needs.resolve-next-release.outputs.next-version != '' && needs.resolve-next-release.outputs.next-version != 'false'
375417
runs-on: ubuntu-latest
376418
concurrency: release-${{ github.ref }}
377419
environment:
@@ -385,6 +427,7 @@ jobs:
385427
pull-requests: write
386428
discussions: write
387429
needs:
430+
- resolve-next-release
388431
- build
389432
- build-binaries
390433
outputs:
@@ -430,13 +473,16 @@ jobs:
430473
run: npx --no vite-node ./scripts/prepareStandalonePrebuiltBinaryModules.ts
431474
- name: Add "postinstall" script to package.json
432475
run: npm run addPostinstallScript
476+
- name: Move semanticReleaseDryRunReleaseResult.json artifact
477+
run: mv artifacts/resolved-next-release/semanticReleaseDryRunReleaseResult.json ./semanticReleaseDryRunReleaseResult.json
433478
- name: Release
434479
env:
435480
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
436481
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
437482
GH_RELEASE_REF: ${{ github.ref }}
438483
run: |
439484
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > ~/.npmrc
485+
export DRY_RUN_RESULT="$(cat ./semanticReleaseDryRunReleaseResult.json)"
440486
441487
npx semantic-release
442488
- name: Set npm package url to GITHUB_OUTPUT
@@ -479,24 +525,20 @@ jobs:
479525
else
480526
npm publish
481527
fi
482-
- name: Generate docs with updated version
483-
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
484-
env:
485-
DOCS_URL_BASE: "/node-llama-cpp/"
486-
run: |
487-
export DOCS_PACKAGE_VERSION=$(cat .semanticRelease.npmPackage.deployedVersion.txt)
488-
npm run docs:build
489-
- name: Upload docs to GitHub Pages
490-
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
491-
uses: actions/upload-pages-artifact@v3
492-
with:
493-
name: pages-docs
494-
path: docs-site
495-
- name: Deploy docs to GitHub Pages
496-
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
497-
uses: actions/deploy-pages@v4
528+
529+
auto-approve-documentation-website-deployment:
530+
name: Auto-approve documentation website deployment
531+
runs-on: ubuntu-latest
532+
continue-on-error: true
533+
needs:
534+
- release
535+
steps:
536+
- name: Approve documentation website deployment
537+
uses: activescott/automate-environment-deployment-approval@v1.0.6
498538
with:
499-
artifact_name: pages-docs
539+
github_token: ${{ secrets.AUTO_APPROVAL_GITHUB_TOKEN }}
540+
environment_allow_list: "Documentation website"
541+
actor_allow_list: giladgd
500542

501543
build-electron-example:
502544
name: Build & release Electron app example - ${{ matrix.config.name }}
@@ -555,6 +597,7 @@ jobs:
555597
- name: Upload artifacts
556598
uses: actions/upload-artifact@v4
557599
with:
600+
include-hidden-files: true
558601
name: "electron-app-example-${{ matrix.config.name }}"
559602
path: "./electron-app-example/release"
560603

@@ -572,3 +615,87 @@ jobs:
572615
done
573616
574617
shopt -u nullglob
618+
619+
update-documentation-website:
620+
name: Update documentation website
621+
if: |
622+
always() &&
623+
github.event_name == 'push' &&
624+
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta') &&
625+
needs.build.result == 'success' &&
626+
needs.resolve-next-release.result == 'success' &&
627+
needs.resolve-next-release.outputs.next-version != '' && (
628+
needs.resolve-next-release.outputs.next-version == 'false' ||
629+
needs.release.result == 'skipped' || (
630+
needs.release.result == 'success' &&
631+
needs.release.outputs.package-version != ''
632+
)
633+
)
634+
runs-on: ubuntu-latest
635+
concurrency: update-documentation-website-${{ github.ref }}
636+
environment:
637+
name: Documentation website
638+
# url: "https://node-llama-cpp.withcat.ai"
639+
needs:
640+
- build
641+
- resolve-next-release
642+
- release
643+
steps:
644+
- uses: actions/checkout@v4
645+
with:
646+
lfs: true
647+
- uses: actions/setup-node@v4
648+
with:
649+
node-version: "20"
650+
- name: Install modules
651+
run: npm ci
652+
- uses: actions/download-artifact@v4
653+
with:
654+
path: artifacts
655+
- name: Move artifacts
656+
run: |
657+
mv artifacts/build dist/
658+
659+
cp -r artifacts/llama.cpp/llama.cpp llama/llama.cpp
660+
661+
rm -f ./llama/binariesGithubRelease.json
662+
mv artifacts/llama.cpp/binariesGithubRelease.json ./llama/binariesGithubRelease.json
663+
664+
rm -f ./llama/llama.cpp.info.json
665+
mv artifacts/llama.cpp/llama.cpp.info.json ./llama/llama.cpp.info.json
666+
- name: Resolve docs version
667+
env:
668+
RELEASE_VERSION: ${{ needs.release.outputs.package-version || needs.resolve-next-release.outputs.next-version }}
669+
run: |
670+
if [ "$RELEASE_VERSION" == "false" ]; then
671+
npx --no vite-node ./scripts/resolveLatestReleaseVersion.ts --saveVersionToFile ./docsVersion.txt
672+
else
673+
echo "$RELEASE_VERSION" > ./docsVersion.txt
674+
fi
675+
- name: Generate docs with updated version
676+
env:
677+
DOCS_URL_BASE: "/"
678+
run: |
679+
export DOCS_PACKAGE_VERSION="$(cat ./docsVersion.txt)"
680+
echo "Package version: $DOCS_PACKAGE_VERSION"
681+
682+
npm run docs:build
683+
- name: Upload docs
684+
uses: actions/upload-artifact@v4
685+
with:
686+
include-hidden-files: true
687+
retention-days: 2
688+
name: "docs-site"
689+
path: docs-site
690+
# - name: Upload docs to GitHub Pages
691+
# uses: actions/upload-pages-artifact@v3
692+
# with:
693+
# name: pages-docs
694+
# path: docs-site
695+
# - name: Deploy docs to GitHub Pages
696+
# uses: actions/deploy-pages@v4
697+
# with:
698+
# artifact_name: pages-docs
699+
# - name: Update feed
700+
# run: |
701+
# curl -X POST "https://pubsubhubbub.appspot.com/" -H "Content-Type: application/x-www-form-urlencoded" --data-urlencode "hub.mode=publish" --data-urlencode "hub.url=https://node-llama-cpp.withcat.ai/blog/feed.atom"

.github/workflows/test.yml

+6
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@ jobs:
3535
node-version: "20"
3636
- name: Install modules
3737
run: npm ci
38+
- name: Build
39+
run: npm run build
40+
- name: Download latest llama.cpp release
41+
env:
42+
CI: true
43+
run: node ./dist/cli/cli.js source download --release latest --skipBuild --noBundle --noUsageExample --updateBinariesReleaseMetadataAndSaveGitBundle
3844
- name: Compile docs
3945
run: npm run docs:build

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ node_modules
1414
/.vitepress/.cache
1515
/test/.models
1616
/test/temp
17+
/temp
1718
/coverage
1819

1920
/llama/compile_commands.json

.husky/commit-msg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npx --no -- commitlint --edit "$1"
1+
commitlint --edit "$1"

0 commit comments

Comments
 (0)