Skip to content

Commit 4757af8

Browse files
authored
feat: automatic batching (#104)
* feat: evaluate multiple sequences in parallel with automatic batching * feat: improve automatic chat wrapper resolution * feat: smart context shifting * feat: improve TS types * refactor: improve API * build: support beta releases * build: improve dev configurations BREAKING CHANGE: completely new API (docs will be updated before a stable version is released)
1 parent 190ef96 commit 4757af8

40 files changed

+5925
-3220
lines changed

.config/typedoc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"preserveAnchorCasing": true,
1919
"useCodeBlocks": true,
2020
"expandObjects": true,
21-
"parametersFormat": "table"
21+
"parametersFormat": "table",
22+
"hideInPageTOC": true
2223
}

.editorconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ insert_final_newline = true
1010
[{package.json,package-lock.json,manifest.json}]
1111
indent_size = 2
1212

13-
[.babelrc]
14-
indent_size = 2
15-
1613
[*.yml]
1714
indent_size = 2

.eslintrc.json

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
},
88
"ignorePatterns": ["/dist", "/llama", "/docs-site"],
99
"extends": [
10-
"eslint:recommended"
10+
"eslint:recommended",
11+
"plugin:jsdoc/recommended"
1112
],
1213
"globals": {
1314
"Atomics": "readonly",
@@ -24,21 +25,31 @@
2425
"files": ["**.ts"],
2526
"extends": [
2627
"eslint:recommended",
27-
"plugin:@typescript-eslint/recommended"
28+
"plugin:@typescript-eslint/recommended",
29+
"plugin:jsdoc/recommended-typescript"
2830
],
2931
"parser": "@typescript-eslint/parser",
3032
"plugins": [
3133
"@typescript-eslint",
3234
"import",
33-
"node"
35+
"jsdoc",
36+
"n"
3437
],
3538
"rules": {
3639
"@typescript-eslint/explicit-module-boundary-types": ["off"],
3740
"@typescript-eslint/ban-ts-comment": ["off"],
3841
"@typescript-eslint/no-explicit-any": ["off"],
3942
"semi": ["off"],
4043
"@typescript-eslint/semi": ["warn", "always"],
41-
"@typescript-eslint/no-inferrable-types": ["off"]
44+
"@typescript-eslint/no-inferrable-types": ["off"],
45+
"jsdoc/require-param": ["off"],
46+
"jsdoc/check-param-names": ["warn", {
47+
"checkDestructured": false
48+
}],
49+
"jsdoc/require-returns": ["off"],
50+
"jsdoc/require-jsdoc": ["off"],
51+
"jsdoc/require-yields": ["off"],
52+
"jsdoc/require-param-description": ["off"]
4253
}
4354
}, {
4455
"files": ["test/**/**.ts"],
@@ -49,11 +60,18 @@
4960
"plugins": [
5061
"@typescript-eslint",
5162
"import",
52-
"node"
63+
"jsdoc",
64+
"n"
5365
],
5466
"settings": {
5567
"import/parsers": {
5668
"@typescript-eslint/parser": [".ts"]
69+
},
70+
"jsdoc": {
71+
"exemptDestructuredRootsFromChecks": true,
72+
"tagNamePreference": {
73+
"hidden": "hidden"
74+
}
5775
}
5876
},
5977
"rules": {
@@ -90,9 +108,7 @@
90108
"groups": ["builtin", "external","internal", "parent", "sibling", "index", "type", "object", "unknown"],
91109
"warnOnUnassignedImports": true
92110
}],
93-
"node/file-extension-in-import": ["error", "always", {
94-
"tryExtensions": [".js", ".json"]
95-
}],
111+
"n/file-extension-in-import": ["error", "always"],
96112
"newline-per-chained-call": ["error", {
97113
"ignoreChainWithDepth": 2
98114
}],
@@ -108,13 +124,6 @@
108124
}],
109125
"no-eval": ["error"],
110126
"array-callback-return": ["error"],
111-
"valid-jsdoc": ["error", {
112-
"requireParamType": true,
113-
"requireReturnType": true,
114-
"requireReturn": false,
115-
"requireParamDescription": false,
116-
"requireReturnDescription": false
117-
}],
118127
"no-empty": ["error", {
119128
"allowEmptyCatch": true
120129
}],

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These are supported funding model platforms
22

3-
github: [giladgd, ido-pluto]
3+
github: giladgd
44
patreon: # Replace with a single Patreon username
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ body:
6868
description: >-
6969
Add any other context about the bug report here.
7070
- type: checkboxes
71-
id: drivers
71+
id: features
7272
attributes:
7373
label: Relevant Features Used
7474
options:

.github/ISSUE_TEMPLATE/feature-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ body:
4343
label: Additional Context
4444
description: Add any other context about the feature request here
4545
- type: checkboxes
46-
id: drivers
46+
id: features
4747
attributes:
4848
label: Related Features to This Feature Request
4949
options:

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ jobs:
239239

240240
release:
241241
name: Release
242-
if: github.ref == 'refs/heads/master'
242+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/beta'
243243
runs-on: ubuntu-latest
244244
concurrency: release-${{ github.ref }}
245245
environment:
@@ -296,20 +296,20 @@ jobs:
296296
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
297297
fi
298298
- name: Generate docs with updated version
299-
if: steps.set-npm-url.outputs.npm-url != ''
299+
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
300300
env:
301301
DOCS_URL_BASE: "/node-llama-cpp/"
302302
run: |
303303
export DOCS_PACKAGE_VERSION=$(cat .semanticRelease.npmPackage.deployedVersion.txt)
304304
npm run docs:build
305305
- name: Upload docs to GitHub Pages
306-
if: steps.set-npm-url.outputs.npm-url != ''
306+
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
307307
uses: actions/upload-pages-artifact@v2
308308
with:
309309
name: pages-docs
310310
path: docs-site
311311
- name: Deploy docs to GitHub Pages
312-
if: steps.set-npm-url.outputs.npm-url != ''
312+
if: steps.set-npm-url.outputs.npm-url != '' && github.ref == 'refs/heads/master'
313313
uses: actions/deploy-pages@v2
314314
with:
315315
artifact_name: pages-docs

.releaserc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"branches": [
3-
"master"
3+
"master",
4+
{"name": "beta", "prerelease": true}
45
],
56
"ci": true,
67
"plugins": [

.vitepress/config.ts

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,17 @@ export default defineConfig({
115115
text: "npm",
116116
link: "https://www.npmjs.com/package/node-llama-cpp"
117117
}, {
118-
text: "Contributing",
118+
text: "Contribute",
119119
link: "/guide/contributing"
120-
}]
120+
},
121+
...(
122+
packageJson?.funding?.url == null
123+
? []
124+
: [{
125+
text: "Sponsor",
126+
link: packageJson?.funding?.url
127+
}]
128+
)]
121129
}
122130
],
123131
search: {
@@ -258,29 +266,37 @@ function orderTypes(sidebar: typeof typedocSidebar) {
258266
if (types == null || !(types.items instanceof Array))
259267
return;
260268

261-
function groupGbnfJsonSchema() {
269+
function groupItems(
270+
findParent: (item: DefaultTheme.SidebarItem) => boolean | undefined,
271+
findChildren: (item: DefaultTheme.SidebarItem) => boolean | undefined,
272+
{collapsed = true, moveToEndIfGrouped = true}: {collapsed?: boolean, moveToEndIfGrouped?: boolean} = {}
273+
) {
274+
const children: DefaultTheme.SidebarItem[] = [];
275+
262276
if (types == null || !(types.items instanceof Array))
263277
return;
264278

265-
const gbnfJsonSchemaItemTitle = "GbnfJsonSchema";
266-
const gbnfItemsPrefix = "GbnfJson";
267-
const gbnfJsonSchemaItems: DefaultTheme.SidebarItem[] = [];
268-
269-
const gbnfJsonSchemaItem = types.items
270-
.find((item) => item.text === gbnfJsonSchemaItemTitle) as DefaultTheme.SidebarItem | null;
279+
const parent = types.items.find(findParent) as DefaultTheme.SidebarItem | null;
271280

272-
if (gbnfJsonSchemaItem == null)
281+
if (parent == null)
273282
return;
274283

275-
gbnfJsonSchemaItem.collapsed = true;
276-
gbnfJsonSchemaItem.items = gbnfJsonSchemaItems;
277-
278284
for (const item of types.items.slice()) {
279-
if (item.text === gbnfJsonSchemaItemTitle || !item.text.startsWith(gbnfItemsPrefix))
285+
if (item === parent || !findChildren(item))
280286
continue;
281287

282288
types.items.splice(types.items.indexOf(item), 1);
283-
gbnfJsonSchemaItems.push(item);
289+
children.push(item);
290+
}
291+
292+
if (children.length > 0) {
293+
parent.collapsed = collapsed;
294+
parent.items = children;
295+
296+
if (moveToEndIfGrouped) {
297+
types.items.splice(types.items.indexOf(parent as typeof types.items[number]), 1);
298+
types.items.push(parent as typeof types.items[number]);
299+
}
284300
}
285301
}
286302

@@ -298,6 +314,24 @@ function orderTypes(sidebar: typeof typedocSidebar) {
298314
});
299315
}
300316

301-
groupGbnfJsonSchema();
317+
groupItems(
318+
(item) => item.text === "BatchingOptions",
319+
(item) => (
320+
item.text === "BatchItem" ||
321+
item.text === "CustomBatchingDispatchSchedule" ||
322+
item.text === "CustomBatchingPrioritizeStrategy" ||
323+
item.text === "PrioritizedBatchItem"
324+
),
325+
{collapsed: false}
326+
);
327+
groupItems(
328+
(item) => item.text === "LlamaContextOptions",
329+
(item) => item.text === "BatchingOptions"
330+
);
331+
groupItems(
332+
(item) => item.text === "GbnfJsonSchema",
333+
(item) => item.text?.startsWith("GbnfJson")
334+
);
335+
302336
moveCollapseItemsToTheEnd();
303337
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
[![Build](https://github.com/withcatai/node-llama-cpp/actions/workflows/build.yml/badge.svg)](https://github.com/withcatai/node-llama-cpp/actions/workflows/build.yml)
1212
[![License](https://badgen.net/badge/color/MIT/green?label=license)](https://www.npmjs.com/package/node-llama-cpp)
13-
[![License](https://badgen.net/badge/color/TypeScript/blue?label=types)](https://www.npmjs.com/package/node-llama-cpp)
13+
[![Types](https://badgen.net/badge/color/TypeScript/blue?label=types)](https://www.npmjs.com/package/node-llama-cpp)
1414
[![Version](https://badgen.net/npm/v/node-llama-cpp)](https://www.npmjs.com/package/node-llama-cpp)
1515

1616
</div>

0 commit comments

Comments
 (0)