node-llama-cpp 2.5.1 → 2.6.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 +19 -301
- package/dist/chatWrappers/{ChatMLPromptWrapper.d.ts → ChatMLChatPromptWrapper.d.ts} +1 -1
- package/dist/chatWrappers/{ChatMLPromptWrapper.js → ChatMLChatPromptWrapper.js} +2 -2
- package/dist/chatWrappers/ChatMLChatPromptWrapper.js.map +1 -0
- package/dist/chatWrappers/createChatWrapperByBos.js +2 -2
- package/dist/chatWrappers/createChatWrapperByBos.js.map +1 -1
- package/dist/cli/commands/BuildCommand.js +3 -1
- package/dist/cli/commands/BuildCommand.js.map +1 -1
- package/dist/cli/commands/ChatCommand.d.ts +8 -1
- package/dist/cli/commands/ChatCommand.js +88 -21
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/DownloadCommand.d.ts +2 -2
- package/dist/cli/commands/DownloadCommand.js +13 -38
- package/dist/cli/commands/DownloadCommand.js.map +1 -1
- package/dist/config.d.ts +5 -0
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/llamaEvaluator/LlamaBins.d.ts +3 -3
- package/dist/llamaEvaluator/LlamaBins.js +2 -2
- package/dist/llamaEvaluator/LlamaBins.js.map +1 -1
- package/dist/llamaEvaluator/LlamaChatSession.d.ts +79 -2
- package/dist/llamaEvaluator/LlamaChatSession.js +52 -8
- package/dist/llamaEvaluator/LlamaChatSession.js.map +1 -1
- package/dist/llamaEvaluator/LlamaContext.d.ts +60 -3
- package/dist/llamaEvaluator/LlamaContext.js +36 -4
- package/dist/llamaEvaluator/LlamaContext.js.map +1 -1
- package/dist/llamaEvaluator/LlamaGrammar.d.ts +16 -3
- package/dist/llamaEvaluator/LlamaGrammar.js +23 -4
- package/dist/llamaEvaluator/LlamaGrammar.js.map +1 -1
- package/dist/llamaEvaluator/LlamaGrammarEvaluationState.d.ts +14 -0
- package/dist/llamaEvaluator/LlamaGrammarEvaluationState.js +16 -0
- package/dist/llamaEvaluator/LlamaGrammarEvaluationState.js.map +1 -0
- package/dist/llamaEvaluator/LlamaModel.d.ts +46 -14
- package/dist/llamaEvaluator/LlamaModel.js +23 -16
- package/dist/llamaEvaluator/LlamaModel.js.map +1 -1
- package/dist/state.d.ts +2 -0
- package/dist/state.js +8 -0
- package/dist/state.js.map +1 -0
- package/dist/utils/cloneLlamaCppRepo.d.ts +1 -0
- package/dist/utils/cloneLlamaCppRepo.js +62 -0
- package/dist/utils/cloneLlamaCppRepo.js.map +1 -0
- package/dist/utils/compileLLamaCpp.js +23 -5
- package/dist/utils/compileLLamaCpp.js.map +1 -1
- package/dist/utils/getBin.d.ts +21 -13
- package/dist/utils/gitReleaseBundles.d.ts +2 -0
- package/dist/utils/gitReleaseBundles.js +25 -0
- package/dist/utils/gitReleaseBundles.js.map +1 -0
- package/llama/addon.cpp +184 -110
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/toolchains/darwin.host-x64.target-arm64.cmake +8 -0
- package/llama/toolchains/linux.host-arm64.target-x64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm71.cmake +5 -0
- package/llamaBins/linux-arm64/llama-addon.node +0 -0
- package/llamaBins/linux-armv7l/llama-addon.node +0 -0
- package/llamaBins/linux-x64/llama-addon.node +0 -0
- package/llamaBins/mac-arm64/ggml-metal.metal +246 -79
- package/llamaBins/mac-arm64/llama-addon.node +0 -0
- package/llamaBins/mac-x64/ggml-metal.metal +246 -79
- package/llamaBins/mac-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64/llama-addon.node +0 -0
- package/package.json +10 -4
- package/dist/chatWrappers/ChatMLPromptWrapper.js.map +0 -1
- package/llamaBins/linux-ppc64le/llama-addon.node +0 -0
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
export type LlamaModelOptions = {
|
|
2
2
|
/** path to the model on the filesystem */
|
|
3
3
|
modelPath: string;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* If null, a random seed will be used
|
|
6
|
+
* @deprecated use the `seed` option on `LlamaContext` instead
|
|
7
|
+
* @hidden
|
|
8
|
+
* */
|
|
5
9
|
seed?: number | null;
|
|
6
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* text context size
|
|
12
|
+
* @deprecated use the `contextSize` option on `LlamaContext` instead
|
|
13
|
+
* @hidden
|
|
14
|
+
* */
|
|
7
15
|
contextSize?: number;
|
|
8
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* prompt processing batch size
|
|
18
|
+
* @deprecated use the `batchSize` option on `LlamaContext` instead
|
|
19
|
+
* @hidden
|
|
20
|
+
* */
|
|
9
21
|
batchSize?: number;
|
|
10
22
|
/** number of layers to store in VRAM */
|
|
11
23
|
gpuLayers?: number;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
/**
|
|
25
|
+
* number of threads to use to evaluate tokens
|
|
26
|
+
* @deprecated use the `threads` option on `LlamaContext` instead
|
|
27
|
+
* @hidden
|
|
28
|
+
* */
|
|
15
29
|
threads?: number;
|
|
16
30
|
/**
|
|
17
31
|
* Temperature is a hyperparameter that controls the randomness of the generated text.
|
|
@@ -22,6 +36,8 @@ export type LlamaModelOptions = {
|
|
|
22
36
|
* At the extreme, a temperature of 0 will always pick the most likely next token, leading to identical outputs in each run.
|
|
23
37
|
*
|
|
24
38
|
* Set to `0` to disable.
|
|
39
|
+
* @deprecated use the `temperature` option on `LlamaChatSession`'s `prompt` function or `LlamaContext`'s `evaluate` function instead
|
|
40
|
+
* @hidden
|
|
25
41
|
*/
|
|
26
42
|
temperature?: number;
|
|
27
43
|
/**
|
|
@@ -30,6 +46,8 @@ export type LlamaModelOptions = {
|
|
|
30
46
|
* Set to `0` to disable (which uses the full vocabulary).
|
|
31
47
|
*
|
|
32
48
|
* Only relevant when `temperature` is set to a value greater than 0.
|
|
49
|
+
* @deprecated use the `topK` option on `LlamaChatSession`'s `prompt` function or `LlamaContext`'s `evaluate` function instead
|
|
50
|
+
* @hidden
|
|
33
51
|
* */
|
|
34
52
|
topK?: number;
|
|
35
53
|
/**
|
|
@@ -39,11 +57,21 @@ export type LlamaModelOptions = {
|
|
|
39
57
|
* Set to `1` to disable.
|
|
40
58
|
*
|
|
41
59
|
* Only relevant when `temperature` is set to a value greater than `0`.
|
|
42
|
-
*
|
|
60
|
+
* @deprecated use the `topP` option on `LlamaChatSession`'s `prompt` function or `LlamaContext`'s `evaluate` function instead
|
|
61
|
+
* @hidden
|
|
62
|
+
*/
|
|
43
63
|
topP?: number;
|
|
44
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* use fp16 for KV cache
|
|
66
|
+
* @deprecated use the `f16Kv` option on `LlamaContext` instead
|
|
67
|
+
* @hidden
|
|
68
|
+
*/
|
|
45
69
|
f16Kv?: boolean;
|
|
46
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* the llama_eval() call computes all logits, not just the last one
|
|
72
|
+
* @deprecated use the `logitsAll` option on `LlamaContext` instead
|
|
73
|
+
* @hidden
|
|
74
|
+
*/
|
|
47
75
|
logitsAll?: boolean;
|
|
48
76
|
/** only load the vocabulary, no weights */
|
|
49
77
|
vocabOnly?: boolean;
|
|
@@ -51,20 +79,24 @@ export type LlamaModelOptions = {
|
|
|
51
79
|
useMmap?: boolean;
|
|
52
80
|
/** force system to keep model in RAM */
|
|
53
81
|
useMlock?: boolean;
|
|
54
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* embedding mode only
|
|
84
|
+
* @deprecated use the `embedding` option on `LlamaContext` instead
|
|
85
|
+
* @hidden
|
|
86
|
+
*/
|
|
55
87
|
embedding?: boolean;
|
|
56
88
|
};
|
|
57
89
|
export declare class LlamaModel {
|
|
58
90
|
/**
|
|
59
|
-
* options source:
|
|
60
|
-
*
|
|
91
|
+
* > options source:
|
|
92
|
+
* > [github:ggerganov/llama.cpp/llama.h](
|
|
93
|
+
* > https://github.com/ggerganov/llama.cpp/blob/b5ffb2849d23afe73647f68eec7b68187af09be6/llama.h#L102) (`struct llama_context_params`)
|
|
61
94
|
* @param {object} options
|
|
62
95
|
* @param {string} options.modelPath - path to the model on the filesystem
|
|
63
96
|
* @param {number | null} [options.seed] - If null, a random seed will be used
|
|
64
97
|
* @param {number} [options.contextSize] - text context size
|
|
65
98
|
* @param {number} [options.batchSize] - prompt processing batch size
|
|
66
99
|
* @param {number} [options.gpuLayers] - number of layers to store in VRAM
|
|
67
|
-
* @param {boolean} [options.lowVram] - if true, reduce VRAM usage at the cost of performance
|
|
68
100
|
* @param {number} [options.threads] - number of threads to use to evaluate tokens
|
|
69
101
|
* @param {number} [options.temperature] - Temperature is a hyperparameter that controls the randomness of the generated text.
|
|
70
102
|
* It affects the probability distribution of the model's output tokens.
|
|
@@ -93,6 +125,6 @@ export declare class LlamaModel {
|
|
|
93
125
|
* @param {boolean} [options.useMlock] - force system to keep model in RAM
|
|
94
126
|
* @param {boolean} [options.embedding] - embedding mode only
|
|
95
127
|
*/
|
|
96
|
-
constructor({ modelPath, seed, contextSize, batchSize, gpuLayers,
|
|
128
|
+
constructor({ modelPath, seed, contextSize, batchSize, gpuLayers, threads, temperature, topK, topP, f16Kv, logitsAll, vocabOnly, useMmap, useMlock, embedding }: LlamaModelOptions);
|
|
97
129
|
static get systemInfo(): string;
|
|
98
130
|
}
|
|
@@ -5,16 +5,20 @@ import { llamaCppNode, LLAMAModel } from "./LlamaBins.js";
|
|
|
5
5
|
export class LlamaModel {
|
|
6
6
|
/** @internal */
|
|
7
7
|
_model;
|
|
8
|
+
/** @internal */
|
|
9
|
+
_contextOptions;
|
|
10
|
+
/** @internal */
|
|
11
|
+
_evaluationOptions;
|
|
8
12
|
/**
|
|
9
|
-
* options source:
|
|
10
|
-
*
|
|
13
|
+
* > options source:
|
|
14
|
+
* > [github:ggerganov/llama.cpp/llama.h](
|
|
15
|
+
* > https://github.com/ggerganov/llama.cpp/blob/b5ffb2849d23afe73647f68eec7b68187af09be6/llama.h#L102) (`struct llama_context_params`)
|
|
11
16
|
* @param {object} options
|
|
12
17
|
* @param {string} options.modelPath - path to the model on the filesystem
|
|
13
18
|
* @param {number | null} [options.seed] - If null, a random seed will be used
|
|
14
19
|
* @param {number} [options.contextSize] - text context size
|
|
15
20
|
* @param {number} [options.batchSize] - prompt processing batch size
|
|
16
21
|
* @param {number} [options.gpuLayers] - number of layers to store in VRAM
|
|
17
|
-
* @param {boolean} [options.lowVram] - if true, reduce VRAM usage at the cost of performance
|
|
18
22
|
* @param {number} [options.threads] - number of threads to use to evaluate tokens
|
|
19
23
|
* @param {number} [options.temperature] - Temperature is a hyperparameter that controls the randomness of the generated text.
|
|
20
24
|
* It affects the probability distribution of the model's output tokens.
|
|
@@ -43,24 +47,27 @@ export class LlamaModel {
|
|
|
43
47
|
* @param {boolean} [options.useMlock] - force system to keep model in RAM
|
|
44
48
|
* @param {boolean} [options.embedding] - embedding mode only
|
|
45
49
|
*/
|
|
46
|
-
constructor({ modelPath, seed = null, contextSize = 1024 * 4, batchSize, gpuLayers,
|
|
50
|
+
constructor({ modelPath, seed = null, contextSize = 1024 * 4, batchSize, gpuLayers, threads = 6, temperature = 0, topK = 40, topP = 0.95, f16Kv, logitsAll, vocabOnly, useMmap, useMlock, embedding }) {
|
|
47
51
|
this._model = new LLAMAModel(path.resolve(process.cwd(), modelPath), removeNullFields({
|
|
48
|
-
seed: seed != null ? Math.max(-1, seed) : undefined,
|
|
49
|
-
contextSize,
|
|
50
|
-
batchSize,
|
|
51
52
|
gpuLayers,
|
|
52
|
-
lowVram,
|
|
53
|
-
threads,
|
|
54
|
-
temperature,
|
|
55
|
-
topK,
|
|
56
|
-
topP,
|
|
57
|
-
f16Kv,
|
|
58
|
-
logitsAll,
|
|
59
53
|
vocabOnly,
|
|
60
54
|
useMmap,
|
|
61
|
-
useMlock
|
|
62
|
-
embedding
|
|
55
|
+
useMlock
|
|
63
56
|
}));
|
|
57
|
+
this._contextOptions = {
|
|
58
|
+
seed,
|
|
59
|
+
contextSize,
|
|
60
|
+
batchSize,
|
|
61
|
+
f16Kv,
|
|
62
|
+
logitsAll,
|
|
63
|
+
embedding,
|
|
64
|
+
threads
|
|
65
|
+
};
|
|
66
|
+
this._evaluationOptions = {
|
|
67
|
+
temperature,
|
|
68
|
+
topK,
|
|
69
|
+
topP
|
|
70
|
+
};
|
|
64
71
|
}
|
|
65
72
|
static get systemInfo() {
|
|
66
73
|
return llamaCppNode.systemInfo();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LlamaModel.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaModel.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"LlamaModel.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaModel.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,YAAY,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AA0GxD,MAAM,OAAO,UAAU;IACnB,gBAAgB;IACA,MAAM,CAAa;IAEnC,gBAAgB;IACA,eAAe,CAQ7B;IAEF,gBAAgB;IACA,kBAAkB,CAIhC;IAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,YAAmB,EACf,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EACpE,OAAO,GAAG,CAAC,EAAE,WAAW,GAAG,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAC/F;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,EAAE,gBAAgB,CAAC;YAClF,SAAS;YACT,SAAS;YACT,OAAO;YACP,QAAQ;SACX,CAAC,CAAC,CAAC;QAEJ,IAAI,CAAC,eAAe,GAAG;YACnB,IAAI;YACJ,WAAW;YACX,SAAS;YACT,KAAK;YACL,SAAS;YACT,SAAS;YACT,OAAO;SACV,CAAC;QAEF,IAAI,CAAC,kBAAkB,GAAG;YACtB,WAAW;YACX,IAAI;YACJ,IAAI;SACP,CAAC;IACN,CAAC;IAEM,MAAM,KAAK,UAAU;QACxB,OAAO,YAAY,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC;CACJ"}
|
package/dist/state.d.ts
ADDED
package/dist/state.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC,MAAM,UAAU,wBAAwB;IACpC,OAAO,qBAAqB,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACnD,qBAAqB,GAAG,KAAK,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cloneLlamaCppRepo(githubOwner: string, githubRepo: string, tag: string): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import simpleGit from "simple-git";
|
|
2
|
+
import cliProgress from "cli-progress";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import { llamaCppDirectory } from "../config.js";
|
|
6
|
+
import { getGitBundlePathForRelease } from "./gitReleaseBundles.js";
|
|
7
|
+
export async function cloneLlamaCppRepo(githubOwner, githubRepo, tag) {
|
|
8
|
+
const gitBundleForTag = await getGitBundlePathForRelease(githubOwner, githubRepo, tag);
|
|
9
|
+
const remoteGitUrl = `https://github.com/${githubOwner}/${githubRepo}.git`;
|
|
10
|
+
async function withGitCloneProgress(cloneName, callback) {
|
|
11
|
+
const progressBar = new cliProgress.Bar({
|
|
12
|
+
clearOnComplete: false,
|
|
13
|
+
hideCursor: true,
|
|
14
|
+
autopadding: true,
|
|
15
|
+
format: `${chalk.bold("Clone {repo}")} ${chalk.yellow("{percentage}%")} ${chalk.cyan("{bar}")} ${chalk.grey("{eta_formatted}")}`
|
|
16
|
+
}, cliProgress.Presets.shades_classic);
|
|
17
|
+
progressBar.start(100, 0, {
|
|
18
|
+
speed: "",
|
|
19
|
+
repo: `${githubOwner}/${githubRepo} (${cloneName})`
|
|
20
|
+
});
|
|
21
|
+
const gitWithCloneProgress = simpleGit({
|
|
22
|
+
progress({ progress, total, processed }) {
|
|
23
|
+
const totalProgress = (processed / 100) + (progress / total);
|
|
24
|
+
progressBar.update(Math.floor(totalProgress * 10000) / 100);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const res = await callback(gitWithCloneProgress);
|
|
29
|
+
progressBar.update(100);
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
progressBar.stop();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (gitBundleForTag != null) {
|
|
37
|
+
try {
|
|
38
|
+
await withGitCloneProgress("local bundle", async (gitWithCloneProgress) => {
|
|
39
|
+
await gitWithCloneProgress.clone(gitBundleForTag, llamaCppDirectory, {
|
|
40
|
+
"--quiet": null
|
|
41
|
+
});
|
|
42
|
+
await simpleGit(llamaCppDirectory)
|
|
43
|
+
.removeRemote("origin");
|
|
44
|
+
await simpleGit(llamaCppDirectory)
|
|
45
|
+
.addRemote("origin", remoteGitUrl);
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
await fs.remove(llamaCppDirectory);
|
|
51
|
+
console.error("Failed to clone git bundle, cloning from GitHub instead", err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
await withGitCloneProgress("GitHub", async (gitWithCloneProgress) => {
|
|
55
|
+
await gitWithCloneProgress.clone(remoteGitUrl, llamaCppDirectory, {
|
|
56
|
+
"--depth": 1,
|
|
57
|
+
"--branch": tag,
|
|
58
|
+
"--quiet": null
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=cloneLlamaCppRepo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneLlamaCppRepo.js","sourceRoot":"","sources":["../../src/utils/cloneLlamaCppRepo.ts"],"names":[],"mappings":"AAAA,OAAO,SAAsB,MAAM,YAAY,CAAC;AAChD,OAAO,WAAW,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAC,0BAA0B,EAAC,MAAM,wBAAwB,CAAC;AAGlE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,WAAmB,EAAE,UAAkB,EAAE,GAAW;IACxF,MAAM,eAAe,GAAG,MAAM,0BAA0B,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IACvF,MAAM,YAAY,GAAG,sBAAsB,WAAW,IAAI,UAAU,MAAM,CAAC;IAE3E,KAAK,UAAU,oBAAoB,CAAI,SAAiB,EAAE,QAAyD;QAC/G,MAAM,WAAW,GAAG,IAAI,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BACjE,SAAS,EAAE,IAAI;iBAClB,CAAC,CAAC;gBAEH,MAAM,SAAS,CAAC,iBAAiB,CAAC;qBAC7B,YAAY,CAAC,QAAQ,CAAC,CAAC;gBAC5B,MAAM,SAAS,CAAC,iBAAiB,CAAC;qBAC7B,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;YACH,OAAO;SACV;QAAC,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACnC,OAAO,CAAC,KAAK,CAAC,yDAAyD,EAAE,GAAG,CAAC,CAAC;SACjF;KACJ;IAED,MAAM,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE;QAChE,MAAM,oBAAoB,CAAC,KAAK,CAAC,YAAY,EAAE,iBAAiB,EAAE;YAC9D,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,GAAG;YACf,SAAS,EAAE,IAAI;SAClB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import process from "process";
|
|
4
4
|
import fs from "fs-extra";
|
|
5
|
-
import { customCmakeOptionsEnvVarPrefix, llamaCppDirectory, llamaDirectory } from "../config.js";
|
|
5
|
+
import { customCmakeOptionsEnvVarPrefix, llamaCppDirectory, llamaDirectory, llamaToolchainsDirectory } from "../config.js";
|
|
6
6
|
import { clearLlamaBuild } from "./clearLlamaBuild.js";
|
|
7
7
|
import { setUsedBinFlag } from "./usedBinFlag.js";
|
|
8
8
|
import { spawnCommand } from "./spawnCommand.js";
|
|
@@ -14,6 +14,7 @@ export async function compileLlamaCpp({ arch = process.arch, nodeTarget = proces
|
|
|
14
14
|
throw new Error(`"${llamaCppDirectory}" directory does not exist`);
|
|
15
15
|
}
|
|
16
16
|
const cmakePathArgs = await getCmakePathArgs();
|
|
17
|
+
const toolchainFile = await getToolchainFileForArch(arch);
|
|
17
18
|
const runtimeVersion = nodeTarget.startsWith("v") ? nodeTarget.slice("v".length) : nodeTarget;
|
|
18
19
|
const cmakeCustomOptions = [];
|
|
19
20
|
if ((metal && process.platform === "darwin") || process.env.LLAMA_METAL === "1")
|
|
@@ -44,6 +45,8 @@ export async function compileLlamaCpp({ arch = process.arch, nodeTarget = proces
|
|
|
44
45
|
cmakeCustomOptions.push("LLAMA_HIPBLAS=1");
|
|
45
46
|
if (process.env.LLAMA_CLBLAST === "1")
|
|
46
47
|
cmakeCustomOptions.push("LLAMA_CLBLAST=1");
|
|
48
|
+
if (toolchainFile != null)
|
|
49
|
+
cmakeCustomOptions.push("CMAKE_TOOLCHAIN_FILE=" + toolchainFile);
|
|
47
50
|
for (const key in process.env) {
|
|
48
51
|
if (key.startsWith(customCmakeOptionsEnvVarPrefix)) {
|
|
49
52
|
const option = key.slice(customCmakeOptionsEnvVarPrefix.length);
|
|
@@ -56,7 +59,7 @@ export async function compileLlamaCpp({ arch = process.arch, nodeTarget = proces
|
|
|
56
59
|
await spawnCommand("npm", ["run", "-s", "cmake-js-llama", "--", "compile", "--log-level", "warn", "--arch=" + arch, "--runtime-version=" + runtimeVersion, ...cmakePathArgs]
|
|
57
60
|
.concat(cmakeCustomOptions.map(option => "--CD" + option)), __dirname);
|
|
58
61
|
const binFilesDirPath = path.join(llamaDirectory, "build", "llama.cpp", "bin");
|
|
59
|
-
const compiledResultDirPath = await getCompiledResultDir();
|
|
62
|
+
const compiledResultDirPath = await getCompiledResultDir(true);
|
|
60
63
|
if (await fs.pathExists(binFilesDirPath)) {
|
|
61
64
|
const files = await fs.readdir(binFilesDirPath);
|
|
62
65
|
await Promise.all(files.map((fileName) => (fs.copy(path.join(binFilesDirPath, fileName), path.join(compiledResultDirPath, fileName), {
|
|
@@ -77,20 +80,24 @@ export async function compileLlamaCpp({ arch = process.arch, nodeTarget = proces
|
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
export async function getCompiledLlamaCppBinaryPath() {
|
|
80
|
-
const compiledResultDirPath = await getCompiledResultDir();
|
|
83
|
+
const compiledResultDirPath = await getCompiledResultDir(false);
|
|
84
|
+
if (compiledResultDirPath == null)
|
|
85
|
+
return null;
|
|
81
86
|
const modulePath = path.join(compiledResultDirPath, "llama-addon.node");
|
|
82
87
|
if (await fs.pathExists(modulePath))
|
|
83
88
|
return modulePath;
|
|
84
89
|
return null;
|
|
85
90
|
}
|
|
86
|
-
async function getCompiledResultDir() {
|
|
91
|
+
async function getCompiledResultDir(failIfNotFound = false) {
|
|
87
92
|
if (await fs.pathExists(path.join(llamaDirectory, "build", "Release"))) {
|
|
88
93
|
return path.join(llamaDirectory, "build", "Release");
|
|
89
94
|
}
|
|
90
95
|
else if (await fs.pathExists(path.join(llamaDirectory, "build", "Debug"))) {
|
|
91
96
|
return path.join(llamaDirectory, "build", "Debug");
|
|
92
97
|
}
|
|
93
|
-
|
|
98
|
+
if (failIfNotFound)
|
|
99
|
+
throw new Error("Could not find Release or Debug directory");
|
|
100
|
+
return null;
|
|
94
101
|
}
|
|
95
102
|
async function getCmakePathArgs() {
|
|
96
103
|
if (await hasBuiltinCmake())
|
|
@@ -100,4 +107,15 @@ async function getCmakePathArgs() {
|
|
|
100
107
|
return [];
|
|
101
108
|
return ["--cmake-path", cmakePath];
|
|
102
109
|
}
|
|
110
|
+
async function getToolchainFileForArch(targetArch) {
|
|
111
|
+
if (process.arch === targetArch)
|
|
112
|
+
return null;
|
|
113
|
+
const platform = process.platform;
|
|
114
|
+
const hostArch = process.arch;
|
|
115
|
+
const toolchainFilename = `${platform}.host-${hostArch}.target-${targetArch}.cmake`;
|
|
116
|
+
const filePath = path.join(llamaToolchainsDirectory, toolchainFilename);
|
|
117
|
+
if (await fs.pathExists(filePath))
|
|
118
|
+
return filePath;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
103
121
|
//# sourceMappingURL=compileLLamaCpp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileLLamaCpp.js","sourceRoot":"","sources":["../../src/utils/compileLLamaCpp.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAClC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,8BAA8B,EAAE,iBAAiB,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"compileLLamaCpp.js","sourceRoot":"","sources":["../../src/utils/compileLLamaCpp.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAClC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,8BAA8B,EAAE,iBAAiB,EAAE,cAAc,EAAE,wBAAwB,EAAC,MAAM,cAAc,CAAC;AACzH,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAC,MAAM,YAAY,CAAC;AAE9E,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/D,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,EAClC,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,iBAAiB,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAClI,IAA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,IAAI,cAAc;QACd,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAEjE,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,gBAAgB;IAC3B,IAAI,MAAM,eAAe,EAAE;QACvB,OAAO,EAAE,CAAC;IAEd,MAAM,SAAS,GAAG,MAAM,YAAY,EAAE,CAAC;IAEvC,IAAI,SAAS,IAAI,IAAI;QACjB,OAAO,EAAE,CAAC;IAEd,OAAO,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,UAAkB;IACrD,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU;QAC3B,OAAO,IAAI,CAAC;IAEhB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAE9B,MAAM,iBAAiB,GAAG,GAAG,QAAQ,SAAS,QAAQ,WAAW,UAAU,QAAQ,CAAC;IAEpF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,CAAC;IAExE,IAAI,MAAM,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC7B,OAAO,QAAQ,CAAC;IAEpB,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
package/dist/utils/getBin.d.ts
CHANGED
|
@@ -4,33 +4,38 @@ export type LlamaCppNodeModule = {
|
|
|
4
4
|
LLAMAModel: LLAMAModel;
|
|
5
5
|
LLAMAContext: LLAMAContext;
|
|
6
6
|
LLAMAGrammar: LLAMAGrammar;
|
|
7
|
+
LLAMAGrammarEvaluationState: LLAMAGrammarEvaluationState;
|
|
7
8
|
systemInfo(): string;
|
|
8
9
|
};
|
|
9
10
|
export type LLAMAModel = {
|
|
10
11
|
new (modelPath: string, params: {
|
|
12
|
+
gpuLayers?: number;
|
|
13
|
+
vocabOnly?: boolean;
|
|
14
|
+
useMmap?: boolean;
|
|
15
|
+
useMlock?: boolean;
|
|
16
|
+
}): LLAMAModel;
|
|
17
|
+
};
|
|
18
|
+
export type LLAMAContext = {
|
|
19
|
+
new (model: LLAMAModel, params: {
|
|
11
20
|
seed?: number;
|
|
12
21
|
contextSize?: number;
|
|
13
22
|
batchSize?: number;
|
|
14
|
-
gpuCores?: number;
|
|
15
|
-
lowVram?: boolean;
|
|
16
23
|
f16Kv?: boolean;
|
|
17
24
|
logitsAll?: boolean;
|
|
18
|
-
vocabOnly?: boolean;
|
|
19
|
-
useMmap?: boolean;
|
|
20
|
-
useMlock?: boolean;
|
|
21
25
|
embedding?: boolean;
|
|
22
26
|
threads?: number;
|
|
27
|
+
}): LLAMAContext;
|
|
28
|
+
encode(text: string): Uint32Array;
|
|
29
|
+
eval(tokens: Uint32Array, options?: {
|
|
23
30
|
temperature?: number;
|
|
24
31
|
topK?: number;
|
|
25
32
|
topP?: number;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}):
|
|
32
|
-
encode(text: string): Uint32Array;
|
|
33
|
-
eval(tokens: Uint32Array): Promise<number>;
|
|
33
|
+
repeatPenalty?: number;
|
|
34
|
+
repeatPenaltyTokens?: Uint32Array;
|
|
35
|
+
repeatPenaltyPresencePenalty?: number;
|
|
36
|
+
repeatPenaltyFrequencyPenalty?: number;
|
|
37
|
+
grammarEvaluationState?: LLAMAGrammarEvaluationState;
|
|
38
|
+
}): Promise<number>;
|
|
34
39
|
decode(tokens: Uint32Array): string;
|
|
35
40
|
tokenBos(): number;
|
|
36
41
|
tokenEos(): number;
|
|
@@ -43,3 +48,6 @@ export type LLAMAGrammar = {
|
|
|
43
48
|
printGrammar?: boolean;
|
|
44
49
|
}): LLAMAGrammar;
|
|
45
50
|
};
|
|
51
|
+
export type LLAMAGrammarEvaluationState = {
|
|
52
|
+
new (grammar: LLAMAGrammar): LLAMAGrammarEvaluationState;
|
|
53
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import simpleGit from "simple-git";
|
|
3
|
+
import { currentReleaseGitBundlePath, defaultLlamaCppGitHubRepo, llamaCppDirectory } from "../config.js";
|
|
4
|
+
import { getBinariesGithubRelease } from "./binariesGithubRelease.js";
|
|
5
|
+
export async function saveCurrentRepoAsReleaseBundle() {
|
|
6
|
+
if (!(await fs.pathExists(llamaCppDirectory)))
|
|
7
|
+
throw new Error("llama.cpp directory does not exist");
|
|
8
|
+
if (await fs.pathExists(currentReleaseGitBundlePath))
|
|
9
|
+
await fs.remove(currentReleaseGitBundlePath);
|
|
10
|
+
await simpleGit(llamaCppDirectory).raw(["bundle", "create", currentReleaseGitBundlePath, "HEAD"]);
|
|
11
|
+
}
|
|
12
|
+
export async function getGitBundlePathForRelease(githubOwner, githubRepo, release) {
|
|
13
|
+
const [defaultGithubOwner, defaultGithubRepo] = defaultLlamaCppGitHubRepo.split("/");
|
|
14
|
+
if (githubOwner !== defaultGithubOwner || githubRepo !== defaultGithubRepo)
|
|
15
|
+
return null;
|
|
16
|
+
const currentBundleRelease = await getBinariesGithubRelease();
|
|
17
|
+
if (currentBundleRelease === "latest")
|
|
18
|
+
return null;
|
|
19
|
+
if (currentBundleRelease !== release)
|
|
20
|
+
return null;
|
|
21
|
+
if (!(await fs.pathExists(currentReleaseGitBundlePath)))
|
|
22
|
+
return null;
|
|
23
|
+
return currentReleaseGitBundlePath;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=gitReleaseBundles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitReleaseBundles.js","sourceRoot":"","sources":["../../src/utils/gitReleaseBundles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,2BAA2B,EAAE,yBAAyB,EAAE,iBAAiB,EAAC,MAAM,cAAc,CAAC;AACvG,O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