node-llama-cpp 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -14
- package/dist/AbortError.d.ts +0 -1
- package/dist/AbortError.js +1 -0
- package/dist/AbortError.js.map +1 -1
- package/dist/cli/commands/ChatCommand.d.ts +1 -0
- package/dist/cli/commands/ChatCommand.js +14 -5
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/llamaEvaluator/LlamaChatSession.js +1 -1
- package/dist/llamaEvaluator/LlamaChatSession.js.map +1 -1
- package/dist/llamaEvaluator/LlamaContext.d.ts +5 -8
- package/dist/llamaEvaluator/LlamaContext.js +3 -4
- package/dist/llamaEvaluator/LlamaContext.js.map +1 -1
- package/dist/llamaEvaluator/LlamaModel.d.ts +29 -6
- package/dist/llamaEvaluator/LlamaModel.js +41 -12
- package/dist/llamaEvaluator/LlamaModel.js.map +1 -1
- package/dist/utils/getBin.d.ts +13 -1
- package/llama/addon.cpp +73 -14
- package/llamaBins/linux-arm64-16.node +0 -0
- package/llamaBins/linux-arm64-17.node +0 -0
- package/llamaBins/linux-arm64-18.node +0 -0
- package/llamaBins/linux-arm64-19.node +0 -0
- package/llamaBins/linux-arm64-20.node +0 -0
- package/llamaBins/linux-armv7l-16.node +0 -0
- package/llamaBins/linux-armv7l-17.node +0 -0
- package/llamaBins/linux-armv7l-18.node +0 -0
- package/llamaBins/linux-armv7l-19.node +0 -0
- package/llamaBins/linux-armv7l-20.node +0 -0
- package/llamaBins/linux-ppc64le-16.node +0 -0
- package/llamaBins/linux-ppc64le-17.node +0 -0
- package/llamaBins/linux-ppc64le-18.node +0 -0
- package/llamaBins/linux-ppc64le-19.node +0 -0
- package/llamaBins/linux-ppc64le-20.node +0 -0
- package/llamaBins/linux-x64-16.node +0 -0
- package/llamaBins/linux-x64-17.node +0 -0
- package/llamaBins/linux-x64-18.node +0 -0
- package/llamaBins/linux-x64-19.node +0 -0
- package/llamaBins/linux-x64-20.node +0 -0
- package/llamaBins/mac-arm64-16.node +0 -0
- package/llamaBins/mac-arm64-17.node +0 -0
- package/llamaBins/mac-arm64-18.node +0 -0
- package/llamaBins/mac-arm64-19.node +0 -0
- package/llamaBins/mac-arm64-20.node +0 -0
- package/llamaBins/mac-x64-16.node +0 -0
- package/llamaBins/mac-x64-17.node +0 -0
- package/llamaBins/mac-x64-18.node +0 -0
- package/llamaBins/mac-x64-19.node +0 -0
- package/llamaBins/mac-x64-20.node +0 -0
- package/llamaBins/win-x64-16.node +0 -0
- package/llamaBins/win-x64-17.node +0 -0
- package/llamaBins/win-x64-18.node +0 -0
- package/llamaBins/win-x64-19.node +0 -0
- package/llamaBins/win-x64-20.node +0 -0
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ If binaries are not available for your platform, it'll fallback to download the
|
|
|
18
18
|
To disable this behavior set the environment variable `NODE_LLAMA_CPP_SKIP_DOWNLOAD` to `true`.
|
|
19
19
|
|
|
20
20
|
## Documentation
|
|
21
|
+
### [API reference](https://withcatai.github.io/node-llama-cpp/modules.html)
|
|
22
|
+
|
|
21
23
|
### Usage
|
|
22
24
|
#### As a chatbot
|
|
23
25
|
```typescript
|
|
@@ -29,8 +31,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
29
31
|
|
|
30
32
|
const model = new LlamaModel({
|
|
31
33
|
modelPath: path.join(__dirname, "models", "vicuna-13b-v1.5-16k.ggmlv3.q5_1.bin")
|
|
32
|
-
})
|
|
33
|
-
const
|
|
34
|
+
});
|
|
35
|
+
const context = new LlamaContext({model});
|
|
36
|
+
const session = new LlamaChatSession({context});
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
const q1 = "Hi there, how are you?";
|
|
@@ -73,7 +76,8 @@ const model = new LlamaModel({
|
|
|
73
76
|
modelPath: path.join(__dirname, "models", "vicuna-13b-v1.5-16k.ggmlv3.q5_1.bin"),
|
|
74
77
|
promptWrapper: new MyCustomChatPromptWrapper() // by default, LlamaChatPromptWrapper is used
|
|
75
78
|
})
|
|
76
|
-
const
|
|
79
|
+
const context = new LlamaContext({model});
|
|
80
|
+
const session = new LlamaChatSession({context});
|
|
77
81
|
|
|
78
82
|
|
|
79
83
|
const q1 = "Hi there, how are you?";
|
|
@@ -98,34 +102,36 @@ import {LlamaModel, LlamaChatSession} from "node-llama-cpp";
|
|
|
98
102
|
|
|
99
103
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
100
104
|
|
|
101
|
-
const model = new
|
|
105
|
+
const model = new LlamaModel({
|
|
102
106
|
modelPath: path.join(__dirname, "models", "vicuna-13b-v1.5-16k.ggmlv3.q5_1.bin")
|
|
103
107
|
});
|
|
104
108
|
|
|
109
|
+
const context = new LlamaContext({model});
|
|
110
|
+
|
|
105
111
|
const q1 = "Hi there, how are you?";
|
|
106
112
|
console.log("AI: " + q1);
|
|
107
113
|
|
|
108
|
-
const tokens =
|
|
114
|
+
const tokens = context.encode(q1);
|
|
109
115
|
const res: number[] = [];
|
|
110
|
-
for await (const chunk of
|
|
116
|
+
for await (const chunk of context.evaluate(tokens)) {
|
|
111
117
|
res.push(chunk);
|
|
112
118
|
|
|
113
119
|
// it's important to not concatinate the results as strings,
|
|
114
120
|
// as doing so will break some characters (like some emojis) that are made of multiple tokens.
|
|
115
121
|
// by using an array of tokens, we can decode them correctly together.
|
|
116
|
-
const resString: string =
|
|
122
|
+
const resString: string = context.decode(Uint32Array.from(res));
|
|
117
123
|
|
|
118
124
|
const lastPart = resString.split("ASSISTANT:").reverse()[0];
|
|
119
125
|
if (lastPart.includes("USER:"))
|
|
120
126
|
break;
|
|
121
127
|
}
|
|
122
128
|
|
|
123
|
-
const a1 =
|
|
129
|
+
const a1 = context.decode(Uint32Array.from(res)).split("USER:")[0];
|
|
124
130
|
console.log("AI: " + a1);
|
|
125
131
|
```
|
|
126
132
|
|
|
127
133
|
### CLI
|
|
128
|
-
```
|
|
134
|
+
```
|
|
129
135
|
Usage: node-llama-cpp <command> [options]
|
|
130
136
|
|
|
131
137
|
Commands:
|
|
@@ -136,11 +142,11 @@ Commands:
|
|
|
136
142
|
|
|
137
143
|
Options:
|
|
138
144
|
-h, --help Show help [boolean]
|
|
139
|
-
-v, --version Show version number [boolean]
|
|
145
|
+
-v, --version Show version number [boolean]
|
|
140
146
|
```
|
|
141
147
|
|
|
142
148
|
#### `download` command
|
|
143
|
-
```
|
|
149
|
+
```
|
|
144
150
|
node-llama-cpp download
|
|
145
151
|
|
|
146
152
|
Download a release of llama.cpp and compile it
|
|
@@ -158,7 +164,7 @@ Options:
|
|
|
158
164
|
```
|
|
159
165
|
|
|
160
166
|
#### `build` command
|
|
161
|
-
```
|
|
167
|
+
```
|
|
162
168
|
node-llama-cpp build
|
|
163
169
|
|
|
164
170
|
Compile the currently downloaded llama.cpp
|
|
@@ -171,7 +177,7 @@ Options:
|
|
|
171
177
|
```
|
|
172
178
|
|
|
173
179
|
#### `clear` command
|
|
174
|
-
```
|
|
180
|
+
```
|
|
175
181
|
node-llama-cpp clear [type]
|
|
176
182
|
|
|
177
183
|
Clear files created by llama-cli
|
|
@@ -183,7 +189,7 @@ Options:
|
|
|
183
189
|
```
|
|
184
190
|
|
|
185
191
|
#### `chat` command
|
|
186
|
-
```
|
|
192
|
+
```
|
|
187
193
|
node-llama-cpp chat
|
|
188
194
|
|
|
189
195
|
Chat with a LLama model
|
package/dist/AbortError.d.ts
CHANGED
package/dist/AbortError.js
CHANGED
package/dist/AbortError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../src/AbortError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC;QACI,KAAK,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;CACJ"}
|
|
1
|
+
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../src/AbortError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IACjC,gBAAgB;IAChB;QACI,KAAK,CAAC,YAAY,CAAC,CAAC;IACxB,CAAC;CACJ"}
|
|
@@ -36,11 +36,17 @@ export const ChatCommand = {
|
|
|
36
36
|
choices: ["general", "llama"],
|
|
37
37
|
description: "Chat wrapper to use",
|
|
38
38
|
group: "Optional:"
|
|
39
|
+
})
|
|
40
|
+
.option("contextSize", {
|
|
41
|
+
type: "number",
|
|
42
|
+
default: 1024 * 4,
|
|
43
|
+
description: "Context size to use for the model",
|
|
44
|
+
group: "Optional:"
|
|
39
45
|
});
|
|
40
46
|
},
|
|
41
|
-
async handler({ model, systemInfo, systemPrompt, wrapper }) {
|
|
47
|
+
async handler({ model, systemInfo, systemPrompt, wrapper, contextSize }) {
|
|
42
48
|
try {
|
|
43
|
-
await RunChat({ model, systemInfo, systemPrompt, wrapper });
|
|
49
|
+
await RunChat({ model, systemInfo, systemPrompt, wrapper, contextSize });
|
|
44
50
|
}
|
|
45
51
|
catch (err) {
|
|
46
52
|
console.error(err);
|
|
@@ -48,14 +54,17 @@ export const ChatCommand = {
|
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
};
|
|
51
|
-
async function RunChat({ model: modelArg, systemInfo, systemPrompt, wrapper }) {
|
|
57
|
+
async function RunChat({ model: modelArg, systemInfo, systemPrompt, wrapper, contextSize }) {
|
|
52
58
|
const { LlamaChatSession } = await import("../../llamaEvaluator/LlamaChatSession.js");
|
|
53
59
|
const { LlamaModel } = await import("../../llamaEvaluator/LlamaModel.js");
|
|
60
|
+
const { LlamaContext } = await import("../../llamaEvaluator/LlamaContext.js");
|
|
54
61
|
const model = new LlamaModel({
|
|
55
|
-
modelPath: modelArg
|
|
62
|
+
modelPath: modelArg,
|
|
63
|
+
contextSize
|
|
56
64
|
});
|
|
65
|
+
const context = new LlamaContext({ model });
|
|
57
66
|
const session = new LlamaChatSession({
|
|
58
|
-
context
|
|
67
|
+
context,
|
|
59
68
|
printLLamaSystemInfo: systemInfo,
|
|
60
69
|
systemPrompt,
|
|
61
70
|
promptWrapper: createChatWrapper(wrapper)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatCommand.js","sourceRoot":"","sources":["../../../src/cli/commands/ChatCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAC,sBAAsB,EAAC,MAAM,8CAA8C,CAAC;AACpF,OAAO,EAAC,wBAAwB,EAAC,MAAM,gDAAgD,CAAC;
|
|
1
|
+
{"version":3,"file":"ChatCommand.js","sourceRoot":"","sources":["../../../src/cli/commands/ChatCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAC,sBAAsB,EAAC,MAAM,8CAA8C,CAAC;AACpF,OAAO,EAAC,wBAAwB,EAAC,MAAM,gDAAgD,CAAC;AAUxF,MAAM,CAAC,MAAM,WAAW,GAAuC;IAC3D,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE,yBAAyB;IACnC,OAAO,CAAC,KAAK;QACT,OAAO,KAAK;aACP,MAAM,CAAC,OAAO,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,IAAI;YAClB,WAAW,EAAE,sCAAsC;YACnD,KAAK,EAAE,WAAW;SACrB,CAAC;aACD,MAAM,CAAC,YAAY,EAAE;YAClB,IAAI,EAAE,SAAS;YACf,O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OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAE3C,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEpE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACjC,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;YAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,GAAG,EAAE,CAAC;KACjB;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe;IACtC,QAAQ,OAAO,EAAE;QACb,KAAK,SAAS;YACV,OAAO,IAAI,wBAAwB,EAAE,CAAC;QAC1C,KAAK,OAAO;YACR,OAAO,IAAI,sBAAsB,EAAE,CAAC;KAC3C;IACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,OAAO,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { withLock } from "../utils/withLock.js";
|
|
|
3
3
|
import { AbortError } from "../AbortError.js";
|
|
4
4
|
import { GeneralChatPromptWrapper } from "../chatWrappers/GeneralChatPromptWrapper.js";
|
|
5
5
|
import { LlamaModel } from "./LlamaModel.js";
|
|
6
|
-
const UNKNOWN_UNICODE_CHAR = "
|
|
6
|
+
const UNKNOWN_UNICODE_CHAR = "\ufffd";
|
|
7
7
|
export class LlamaChatSession {
|
|
8
8
|
_systemPrompt;
|
|
9
9
|
_printLLamaSystemInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlamaChatSession.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaChatSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,wBAAwB,EAAC,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAG3C,MAAM,oBAAoB,GAAG,
|
|
1
|
+
{"version":3,"file":"LlamaChatSession.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaChatSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,wBAAwB,EAAC,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAG3C,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAEtC,MAAM,OAAO,gBAAgB;IACR,aAAa,CAAS;IACtB,qBAAqB,CAAU;IAC/B,cAAc,CAAoB;IAC3C,YAAY,GAAW,CAAC,CAAC;IACzB,YAAY,GAAY,KAAK,CAAC;IACrB,IAAI,CAAe;IAEpC,YAAmB,EACf,OAAO,EACP,oBAAoB,GAAG,KAAK,EAC5B,aAAa,GAAG,IAAI,wBAAwB,EAAE,EAC9C,YAAY,GAAG,uBAAuB,EAMzC;QACG,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;QAClD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QAEpC,IAAI,CAAC,aAAa,GA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C;IAEO,gBAAgB,CAAC,QAAgB,EAAE,iBAA2B;QAClE,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC;QACzD,IAAI,cAAc,GAAG,KAAK,CAAC;QAE3B,KAAK,IAAI,eAAe,GAAG,CAAC,EAAE,eAAe,GAAG,WAAW,CAAC,MAAM,EAAE,eAAe,EAAE,EAAE;YACnF,MAAM,UAAU,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;YAEhD,IAAI,yBAAyB,GAAG,KAAK,CAAC;YACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,IAAI,iBAAiB,CAAC,eAAe,CAAC,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAClG,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,EAAE;oBAChE,iBAAiB,CAAC,eAAe,CAAC,EAAE,CAAC;oBACrC,yBAAyB,GAAG,IAAI,CAAC;iBACpC;qBAAM;oBACH,iBAAiB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oBACvC,yBAAyB,GAAG,KAAK,CAAC;oBAClC,MAAM;iBACT;aACJ;YAED,IAAI,iBAAiB,CAAC,eAAe,CAAC,KAAK,UAAU,CAAC,MAAM,EAAE;gBAC1D,OAAO,EAAC,YAAY,EAAE,IAAI,EAAC,CAAC;aAC/B;YAED,cAAc,KAAK,yBAAyB,CAAC;SAChD;QAED,OAAO,EAAC,cAAc,EAAC,CAAC;IAC5B,CAAC;CACJ"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type LlamaContextConstructorParameters = {
|
|
3
|
-
prependBos: boolean;
|
|
4
|
-
ctx: LLAMAContext;
|
|
5
|
-
};
|
|
1
|
+
import { LlamaModel } from "./LlamaModel.js";
|
|
6
2
|
export declare class LlamaContext {
|
|
7
3
|
private readonly _ctx;
|
|
8
4
|
private _prependBos;
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
constructor({ model, prependBos }: {
|
|
6
|
+
model: LlamaModel;
|
|
7
|
+
prependBos?: boolean;
|
|
8
|
+
});
|
|
11
9
|
encode(text: string): Uint32Array;
|
|
12
10
|
decode(tokens: Uint32Array): string;
|
|
13
11
|
evaluate(tokens: Uint32Array, getRestrictions?: () => Uint32Array): AsyncGenerator<number, void, unknown>;
|
|
14
12
|
}
|
|
15
|
-
export {};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { llamaCppNode } from "./LlamaBins.js";
|
|
1
|
+
import { LLAMAContext, llamaCppNode } from "./LlamaBins.js";
|
|
2
2
|
export class LlamaContext {
|
|
3
3
|
_ctx;
|
|
4
4
|
_prependBos;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this._ctx = ctx;
|
|
5
|
+
constructor({ model, prependBos = true }) {
|
|
6
|
+
this._ctx = new LLAMAContext(model._model);
|
|
8
7
|
this._prependBos = prependBos;
|
|
9
8
|
}
|
|
10
9
|
encode(text) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlamaContext.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaContext.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"LlamaContext.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG1D,MAAM,OAAO,YAAY;IACJ,IAAI,CAAe;IAC5B,WAAW,CAAU;IAE7B,YAAmB,EAAC,KAAK,EAAE,UAAU,GAAG,IAAI,EAA4C;QACpF,IAAI,CAAC,IAAI,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,MAAmB;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAmB,EAAE,eAAmC;QAC3E,IAAI,UAAU,GAAG,MAAM,CAAC;QAExB,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACtC,UAAU,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;YAE5C,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC1C,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;SAC5B;QAED,iDAAiD;QACjD,OAAO,IAAI,EAAE;YACT,kCAAkC;YAClC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC;YAExE,mCAAmC;YACnC,IAAI,SAAS,KAAK,YAAY,CAAC,QAAQ,EAAE;gBACrC,MAAM;YAEV,MAAM,SAAS,CAAC;YAEhB,mCAAmC;YACnC,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;SAC9C;IACL,CAAC;CAEJ"}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
-
import { LlamaContext } from "./LlamaContext.js";
|
|
2
1
|
export declare class LlamaModel {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* options source:
|
|
4
|
+
* https://github.com/ggerganov/llama.cpp/blob/b5ffb2849d23afe73647f68eec7b68187af09be6/llama.h#L102 (struct llama_context_params)
|
|
5
|
+
* @param {object} options
|
|
6
|
+
* @param {string} options.modelPath - path to the model on the filesystem
|
|
7
|
+
* @param {number | null} [options.seed] - If null, a random seed will be used
|
|
8
|
+
* @param {number} [options.contextSize] - text context size
|
|
9
|
+
* @param {number} [options.batchSize] - prompt processing batch size
|
|
10
|
+
* @param {number} [options.gpuCores] - number of layers to store in VRAM
|
|
11
|
+
* @param {boolean} [options.lowVram] - if true, reduce VRAM usage at the cost of performance
|
|
12
|
+
* @param {boolean} [options.f16Kv] - use fp16 for KV cache
|
|
13
|
+
* @param {boolean} [options.logitsAll] - the llama_eval() call computes all logits, not just the last one
|
|
14
|
+
* @param {boolean} [options.vocabOnly] - only load the vocabulary, no weights
|
|
15
|
+
* @param {boolean} [options.useMmap] - use mmap if possible
|
|
16
|
+
* @param {boolean} [options.useMlock] - force system to keep model in RAM
|
|
17
|
+
* @param {boolean} [options.embedding] - embedding mode only
|
|
18
|
+
*/
|
|
19
|
+
constructor({ modelPath, seed, contextSize, batchSize, gpuCores, lowVram, f16Kv, logitsAll, vocabOnly, useMmap, useMlock, embedding }: {
|
|
6
20
|
modelPath: string;
|
|
7
|
-
|
|
21
|
+
seed?: number | null;
|
|
22
|
+
contextSize?: number;
|
|
23
|
+
batchSize?: number;
|
|
24
|
+
gpuCores?: number;
|
|
25
|
+
lowVram?: boolean;
|
|
26
|
+
f16Kv?: boolean;
|
|
27
|
+
logitsAll?: boolean;
|
|
28
|
+
vocabOnly?: boolean;
|
|
29
|
+
useMmap?: boolean;
|
|
30
|
+
useMlock?: boolean;
|
|
31
|
+
embedding?: boolean;
|
|
8
32
|
});
|
|
9
|
-
createContext(): LlamaContext;
|
|
10
33
|
static get systemInfo(): string;
|
|
11
34
|
}
|
|
@@ -1,20 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LLAMAContext, llamaCppNode, LLAMAModel } from "./LlamaBins.js";
|
|
1
|
+
import { llamaCppNode, LLAMAModel } from "./LlamaBins.js";
|
|
3
2
|
export class LlamaModel {
|
|
3
|
+
/** @internal */
|
|
4
4
|
_model;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* options source:
|
|
7
|
+
* https://github.com/ggerganov/llama.cpp/blob/b5ffb2849d23afe73647f68eec7b68187af09be6/llama.h#L102 (struct llama_context_params)
|
|
8
|
+
* @param {object} options
|
|
9
|
+
* @param {string} options.modelPath - path to the model on the filesystem
|
|
10
|
+
* @param {number | null} [options.seed] - If null, a random seed will be used
|
|
11
|
+
* @param {number} [options.contextSize] - text context size
|
|
12
|
+
* @param {number} [options.batchSize] - prompt processing batch size
|
|
13
|
+
* @param {number} [options.gpuCores] - number of layers to store in VRAM
|
|
14
|
+
* @param {boolean} [options.lowVram] - if true, reduce VRAM usage at the cost of performance
|
|
15
|
+
* @param {boolean} [options.f16Kv] - use fp16 for KV cache
|
|
16
|
+
* @param {boolean} [options.logitsAll] - the llama_eval() call computes all logits, not just the last one
|
|
17
|
+
* @param {boolean} [options.vocabOnly] - only load the vocabulary, no weights
|
|
18
|
+
* @param {boolean} [options.useMmap] - use mmap if possible
|
|
19
|
+
* @param {boolean} [options.useMlock] - force system to keep model in RAM
|
|
20
|
+
* @param {boolean} [options.embedding] - embedding mode only
|
|
21
|
+
*/
|
|
22
|
+
constructor({ modelPath, seed = null, contextSize = 1024 * 4, batchSize, gpuCores, lowVram, f16Kv, logitsAll, vocabOnly, useMmap, useMlock, embedding }) {
|
|
23
|
+
this._model = new LLAMAModel(modelPath, removeNullFields({
|
|
24
|
+
seed: seed != null ? Math.max(-1, seed) : undefined,
|
|
25
|
+
contextSize,
|
|
26
|
+
batchSize,
|
|
27
|
+
gpuCores,
|
|
28
|
+
lowVram,
|
|
29
|
+
f16Kv,
|
|
30
|
+
logitsAll,
|
|
31
|
+
vocabOnly,
|
|
32
|
+
useMmap,
|
|
33
|
+
useMlock,
|
|
34
|
+
embedding
|
|
35
|
+
}));
|
|
15
36
|
}
|
|
16
37
|
static get systemInfo() {
|
|
17
38
|
return llamaCppNode.systemInfo();
|
|
18
39
|
}
|
|
19
40
|
}
|
|
41
|
+
function removeNullFields(obj) {
|
|
42
|
+
const newObj = Object.assign({}, obj);
|
|
43
|
+
for (const key in obj) {
|
|
44
|
+
if (newObj[key] == null)
|
|
45
|
+
delete newObj[key];
|
|
46
|
+
}
|
|
47
|
+
return newObj;
|
|
48
|
+
}
|
|
20
49
|
//# sourceMappingURL=LlamaModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlamaModel.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"LlamaModel.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAGxD,MAAM,OAAO,UAAU;IACnB,gBAAgB;IACA,MAAM,CAAa;IAEnC;;;;;;;;;;;;;;;;OAgBG;IACH,YAAmB,EACf,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EACnE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAKrE;QACG,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,SAAS,EAAE,gBAAgB,CAAC;YACrD,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;YACnD,WAAW;YACX,SAAS;YACT,QAAQ;YACR,OAAO;YACP,KAAK;YACL,SAAS;YACT,SAAS;YACT,OAAO;YACP,QAAQ;YACR,SAAS;SACZ,CAAC,CAAC,CAAC;IACR,CAAC;IAEM,MAAM,KAAK,UAAU;QACxB,OAAO,YAAY,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;CACJ;AAED,SAAS,gBAAgB,CAAmB,GAAM;IAC9C,MAAM,MAAM,GAAM,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IAEzC,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;QACnB,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI;YACnB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KAC1B;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/dist/utils/getBin.d.ts
CHANGED
|
@@ -8,7 +8,19 @@ export type LlamaCppNodeModule = {
|
|
|
8
8
|
tokenEos(): number;
|
|
9
9
|
};
|
|
10
10
|
export type LLAMAModel = {
|
|
11
|
-
new (modelPath: string
|
|
11
|
+
new (modelPath: string, params: {
|
|
12
|
+
seed?: number;
|
|
13
|
+
contextSize?: number;
|
|
14
|
+
batchSize?: number;
|
|
15
|
+
gpuCores?: number;
|
|
16
|
+
lowVram?: boolean;
|
|
17
|
+
f16Kv?: boolean;
|
|
18
|
+
logitsAll?: boolean;
|
|
19
|
+
vocabOnly?: boolean;
|
|
20
|
+
useMmap?: boolean;
|
|
21
|
+
useMlock?: boolean;
|
|
22
|
+
embedding?: boolean;
|
|
23
|
+
}): LLAMAModel;
|
|
12
24
|
};
|
|
13
25
|
export type LLAMAContext = {
|
|
14
26
|
new (model: LLAMAModel): LLAMAContext;
|
package/llama/addon.cpp
CHANGED
|
@@ -8,21 +8,80 @@
|
|
|
8
8
|
|
|
9
9
|
class LLAMAModel : public Napi::ObjectWrap<LLAMAModel> {
|
|
10
10
|
public:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
llama_context_params params;
|
|
12
|
+
llama_model* model;
|
|
13
|
+
|
|
14
|
+
LLAMAModel(const Napi::CallbackInfo& info) : Napi::ObjectWrap<LLAMAModel>(info) {
|
|
15
|
+
params = llama_context_default_params();
|
|
16
|
+
params.seed = -1;
|
|
17
|
+
params.n_ctx = 4096;
|
|
18
|
+
|
|
19
|
+
// Get the model path
|
|
20
|
+
std::string modelPath = info[0].As<Napi::String>().Utf8Value();
|
|
21
|
+
|
|
22
|
+
if (info.Length() > 1 && info[1].IsObject()) {
|
|
23
|
+
Napi::Object options = info[1].As<Napi::Object>();
|
|
24
|
+
|
|
25
|
+
if (options.Has("seed")) {
|
|
26
|
+
params.seed = options.Get("seed").As<Napi::Number>().Int32Value();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (options.Has("contextSize")) {
|
|
30
|
+
params.n_ctx = options.Get("contextSize").As<Napi::Number>().Int32Value();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (options.Has("batchSize")) {
|
|
34
|
+
params.n_batch = options.Get("batchSize").As<Napi::Number>().Int32Value();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.Has("gpuCores")) {
|
|
38
|
+
params.n_gpu_layers = options.Get("gpuCores").As<Napi::Number>().Int32Value();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (options.Has("lowVram")) {
|
|
42
|
+
params.low_vram = options.Get("lowVram").As<Napi::Boolean>().Value();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (options.Has("f16Kv")) {
|
|
46
|
+
params.f16_kv = options.Get("f16Kv").As<Napi::Boolean>().Value();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (options.Has("logitsAll")) {
|
|
50
|
+
params.logits_all = options.Get("logitsAll").As<Napi::Boolean>().Value();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.Has("vocabOnly")) {
|
|
54
|
+
params.vocab_only = options.Get("vocabOnly").As<Napi::Boolean>().Value();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (options.Has("useMmap")) {
|
|
58
|
+
params.use_mmap = options.Get("useMmap").As<Napi::Boolean>().Value();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (options.Has("useMlock")) {
|
|
62
|
+
params.use_mlock = options.Get("useMlock").As<Napi::Boolean>().Value();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.Has("embedding")) {
|
|
66
|
+
params.embedding = options.Get("embedding").As<Napi::Boolean>().Value();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
model = llama_load_model_from_file(modelPath.c_str(), params);
|
|
71
|
+
|
|
72
|
+
if (model == NULL) {
|
|
73
|
+
Napi::Error::New(info.Env(), "Failed to load model").ThrowAsJavaScriptException();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
~LLAMAModel() {
|
|
79
|
+
llama_free_model(model);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static void init(Napi::Object exports) {
|
|
83
|
+
exports.Set("LLAMAModel", DefineClass(exports.Env(), "LLAMAModel", {}));
|
|
22
84
|
}
|
|
23
|
-
}
|
|
24
|
-
~LLAMAModel() { llama_free_model(model); }
|
|
25
|
-
static void init(Napi::Object exports) { exports.Set("LLAMAModel", DefineClass(exports.Env(), "LLAMAModel", {})); }
|
|
26
85
|
};
|
|
27
86
|
|
|
28
87
|
class LLAMAContext : public Napi::ObjectWrap<LLAMAContext> {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-llama-cpp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "node.js bindings for llama.cpp",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"prepare": "[ $CI = true ] || [ -d '.husky/_' ] || husky install",
|
|
45
45
|
"prebuild": "rm -rf ./dist ./tsconfig.tsbuildinfo",
|
|
46
46
|
"build": "tsc --build tsconfig.json --force",
|
|
47
|
+
"generate-docs": "typedoc",
|
|
47
48
|
"prewatch": "rm -rf ./dist ./tsconfig.tsbuildinfo",
|
|
48
49
|
"watch": "tsc --build tsconfig.json --watch --force",
|
|
49
50
|
"node-gyp-llama": "cd llama && node-gyp",
|
|
@@ -79,10 +80,11 @@
|
|
|
79
80
|
"bugs": {
|
|
80
81
|
"url": "https://github.com/withcatai/node-llama-cpp/issues"
|
|
81
82
|
},
|
|
82
|
-
"homepage": "https://github.
|
|
83
|
+
"homepage": "https://withcatai.github.io/node-llama-cpp/",
|
|
83
84
|
"devDependencies": {
|
|
84
85
|
"@commitlint/cli": "^17.7.1",
|
|
85
86
|
"@commitlint/config-conventional": "^17.7.0",
|
|
87
|
+
"@semantic-release/exec": "^6.0.3",
|
|
86
88
|
"@types/bytes": "^3.1.1",
|
|
87
89
|
"@types/cli-progress": "^3.11.0",
|
|
88
90
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -99,6 +101,7 @@
|
|
|
99
101
|
"semantic-release": "^21.0.7",
|
|
100
102
|
"ts-node": "^10.9.1",
|
|
101
103
|
"tslib": "^2.6.1",
|
|
104
|
+
"typedoc": "^0.24.8",
|
|
102
105
|
"typescript": "^5.1.6",
|
|
103
106
|
"zx": "^7.2.3"
|
|
104
107
|
},
|