node-llama-cpp 3.17.1 → 3.18.1

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.
Files changed (121) hide show
  1. package/dist/bindings/AddonTypes.d.ts +13 -0
  2. package/dist/bindings/Llama.js +20 -2
  3. package/dist/bindings/Llama.js.map +1 -1
  4. package/dist/bindings/getLlama.d.ts +1 -1
  5. package/dist/bindings/getLlama.js +19 -8
  6. package/dist/bindings/getLlama.js.map +1 -1
  7. package/dist/bindings/utils/compileLLamaCpp.d.ts +2 -1
  8. package/dist/bindings/utils/compileLLamaCpp.js +8 -0
  9. package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
  10. package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +1 -1
  11. package/dist/bindings/utils/getLlamaGpuTypes.js +2 -0
  12. package/dist/bindings/utils/getLlamaGpuTypes.js.map +1 -1
  13. package/dist/chatWrappers/QwenChatWrapper.d.ts +7 -0
  14. package/dist/chatWrappers/QwenChatWrapper.js +176 -56
  15. package/dist/chatWrappers/QwenChatWrapper.js.map +1 -1
  16. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +127 -88
  17. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -1
  18. package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.d.ts +16 -10
  19. package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js +115 -5
  20. package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js.map +1 -1
  21. package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js +1 -0
  22. package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js.map +1 -1
  23. package/dist/cli/commands/ChatCommand.d.ts +3 -0
  24. package/dist/cli/commands/ChatCommand.js +34 -5
  25. package/dist/cli/commands/ChatCommand.js.map +1 -1
  26. package/dist/cli/commands/CompleteCommand.d.ts +3 -0
  27. package/dist/cli/commands/CompleteCommand.js +34 -4
  28. package/dist/cli/commands/CompleteCommand.js.map +1 -1
  29. package/dist/cli/commands/InfillCommand.d.ts +3 -0
  30. package/dist/cli/commands/InfillCommand.js +34 -4
  31. package/dist/cli/commands/InfillCommand.js.map +1 -1
  32. package/dist/cli/commands/OnPostInstallCommand.js +31 -4
  33. package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
  34. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +3 -0
  35. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +28 -1
  36. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -1
  37. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +5 -0
  38. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -1
  39. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +51 -4
  40. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -1
  41. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +3 -0
  42. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +46 -5
  43. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -1
  44. package/dist/cli/utils/interactivelyAskForModel.d.ts +4 -1
  45. package/dist/cli/utils/interactivelyAskForModel.js +21 -7
  46. package/dist/cli/utils/interactivelyAskForModel.js.map +1 -1
  47. package/dist/cli/utils/packageJsonConfig.d.ts +6 -0
  48. package/dist/cli/utils/packageJsonConfig.js +51 -0
  49. package/dist/cli/utils/packageJsonConfig.js.map +1 -0
  50. package/dist/cli/utils/packageManager.d.ts +1 -0
  51. package/dist/cli/utils/packageManager.js +15 -0
  52. package/dist/cli/utils/packageManager.js.map +1 -0
  53. package/dist/cli/utils/printCommonInfoLines.js +9 -0
  54. package/dist/cli/utils/printCommonInfoLines.js.map +1 -1
  55. package/dist/cli/utils/resolveCommandGgufPath.d.ts +4 -1
  56. package/dist/cli/utils/resolveCommandGgufPath.js +9 -2
  57. package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -1
  58. package/dist/cli/utils/resolveNpmrcConfig.d.ts +18 -0
  59. package/dist/cli/utils/resolveNpmrcConfig.js +129 -0
  60. package/dist/cli/utils/resolveNpmrcConfig.js.map +1 -0
  61. package/dist/config.d.ts +6 -1
  62. package/dist/config.js +12 -2
  63. package/dist/config.js.map +1 -1
  64. package/dist/evaluator/LlamaChat/LlamaChat.d.ts +8 -2
  65. package/dist/evaluator/LlamaChat/LlamaChat.js +99 -6
  66. package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
  67. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +8 -2
  68. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
  69. package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +8 -2
  70. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
  71. package/dist/evaluator/LlamaContext/LlamaContext.d.ts +91 -0
  72. package/dist/evaluator/LlamaContext/LlamaContext.js +215 -19
  73. package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
  74. package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.d.ts +27 -0
  75. package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js +130 -0
  76. package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js.map +1 -0
  77. package/dist/evaluator/LlamaContext/types.d.ts +32 -1
  78. package/dist/evaluator/LlamaModel/LlamaModel.d.ts +33 -0
  79. package/dist/evaluator/LlamaModel/LlamaModel.js +24 -3
  80. package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -1
  81. package/dist/gguf/insights/GgufInsights.d.ts +12 -1
  82. package/dist/gguf/insights/GgufInsights.js +246 -49
  83. package/dist/gguf/insights/GgufInsights.js.map +1 -1
  84. package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +13 -4
  85. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +17 -5
  86. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -1
  87. package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +4 -1
  88. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +7 -1
  89. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -1
  90. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +4 -1
  91. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +16 -4
  92. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -1
  93. package/dist/gguf/types/GgufMetadataTypes.d.ts +18 -2
  94. package/dist/gguf/types/GgufMetadataTypes.js +6 -0
  95. package/dist/gguf/types/GgufMetadataTypes.js.map +1 -1
  96. package/dist/gguf/types/GgufTensorInfoTypes.d.ts +4 -2
  97. package/dist/gguf/types/GgufTensorInfoTypes.js +11 -1
  98. package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -1
  99. package/dist/gguf/utils/getGgufFileTypeName.d.ts +1 -1
  100. package/dist/gguf/utils/ggufQuantNames.js +1 -0
  101. package/dist/gguf/utils/ggufQuantNames.js.map +1 -1
  102. package/dist/tsconfig.tsbuildinfo +1 -1
  103. package/dist/types.d.ts +1 -0
  104. package/dist/utils/getBuildDefaults.d.ts +1 -1
  105. package/dist/utils/getFirstWritableDir.d.ts +8 -0
  106. package/dist/utils/getFirstWritableDir.js +60 -0
  107. package/dist/utils/getFirstWritableDir.js.map +1 -0
  108. package/dist/utils/getTempDir.d.ts +10 -0
  109. package/dist/utils/getTempDir.js +121 -0
  110. package/dist/utils/getTempDir.js.map +1 -0
  111. package/dist/utils/prettyPrintObject.js +1 -1
  112. package/dist/utils/prettyPrintObject.js.map +1 -1
  113. package/dist/utils/resolveModelFile.js +19 -8
  114. package/dist/utils/resolveModelFile.js.map +1 -1
  115. package/llama/addon/AddonContext.cpp +182 -0
  116. package/llama/addon/AddonContext.h +27 -0
  117. package/llama/addon/addon.cpp +1 -0
  118. package/llama/binariesGithubRelease.json +1 -1
  119. package/llama/gitRelease.bundle +0 -0
  120. package/llama/llama.cpp.info.json +1 -1
  121. package/package.json +24 -24
@@ -0,0 +1,129 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import fs from "fs-extra";
4
+ import { getPlatform } from "../../bindings/utils/getPlatform.js";
5
+ const defaultNpmRegistry = "https://registry.npmjs.org/";
6
+ export async function getCurrentNpmrcConfig() {
7
+ const layers = await getNpmConfigLayers(process.cwd());
8
+ const mergedConfig = {
9
+ ...layers.builtin,
10
+ ...layers.global,
11
+ ...layers.user,
12
+ ...layers.project,
13
+ ...layers.env
14
+ };
15
+ return mergedConfig;
16
+ }
17
+ export function getNpmrcRegistry(npmrcConfig) {
18
+ const registryUrl = npmrcConfig.registry ?? defaultNpmRegistry;
19
+ let cleanRegistryUrl = registryUrl;
20
+ try {
21
+ const url = new URL(registryUrl);
22
+ url.search = "";
23
+ url.hash = "";
24
+ cleanRegistryUrl = url.href;
25
+ }
26
+ catch (err) {
27
+ // do nothing
28
+ }
29
+ if (!cleanRegistryUrl.endsWith("/"))
30
+ cleanRegistryUrl += "/";
31
+ return {
32
+ isDefault: cleanRegistryUrl === defaultNpmRegistry,
33
+ registryUrl,
34
+ cleanRegistryUrl: cleanRegistryUrl
35
+ };
36
+ }
37
+ async function findNearestProjectNpmrc(startDir) {
38
+ let currentDirPath = path.resolve(startDir);
39
+ while (true) {
40
+ const npmrcPath = path.join(currentDirPath, ".npmrc");
41
+ if (await fs.pathExists(npmrcPath))
42
+ return npmrcPath;
43
+ const parentDirPath = path.dirname(currentDirPath);
44
+ if (parentDirPath === currentDirPath)
45
+ return undefined;
46
+ currentDirPath = parentDirPath;
47
+ }
48
+ }
49
+ function parseNpmrc(content, env = process.env) {
50
+ const result = {};
51
+ for (const rawLine of content.split(/\r?\n/u)) {
52
+ const line = rawLine.trim();
53
+ if (line === "" || line.startsWith(";") || line.startsWith("#"))
54
+ continue;
55
+ const eqIndex = line.indexOf("=");
56
+ if (eqIndex <= 0)
57
+ continue;
58
+ const key = line.slice(0, eqIndex).trim();
59
+ const value = line.slice(eqIndex + 1)
60
+ .trim()
61
+ .replace(/\$\{([^}]+)\}/gu, (match, envVarName) => (env[envVarName] ?? ""));
62
+ result[key] = value;
63
+ }
64
+ return result;
65
+ }
66
+ async function readNpmrc(filePath) {
67
+ if (filePath == null || !(await fs.pathExists(filePath)))
68
+ return {};
69
+ return parseNpmrc(fs.readFileSync(filePath, "utf8"));
70
+ }
71
+ async function getDefaultGlobalConfigPath(npmPrefixConfig) {
72
+ const prefix = npmPrefixConfig ?? process.env.PREFIX;
73
+ if (prefix != null && prefix !== "")
74
+ return path.join(prefix, "etc", "npmrc");
75
+ const platform = getPlatform();
76
+ if (platform === "win") {
77
+ const appData = process.env.APPDATA;
78
+ if (appData != null && appData !== "")
79
+ return path.join(appData, "npm", "etc", "npmrc");
80
+ }
81
+ else if (platform === "mac") {
82
+ const npmrcLocations = [
83
+ "/opt/homebrew/etc/npmrc",
84
+ "/usr/local/etc/npmrc"
85
+ ];
86
+ for (const candidate of npmrcLocations) {
87
+ if (await fs.pathExists(candidate))
88
+ return candidate;
89
+ }
90
+ }
91
+ else if (platform === "linux")
92
+ return "/etc/npmrc";
93
+ return undefined;
94
+ }
95
+ async function getNpmConfigLayers(startDir) {
96
+ const envConfig = {};
97
+ for (const [key, value] of Object.entries(process.env)) {
98
+ if (value == null)
99
+ continue;
100
+ const lowerKey = key.toLowerCase();
101
+ if (lowerKey.startsWith("npm_config_")) {
102
+ const configKey = lowerKey.slice("npm_config_".length).replaceAll("_", "-");
103
+ envConfig[configKey] = value;
104
+ }
105
+ }
106
+ const globalConfigPath = envConfig["globalconfig"] ?? await getDefaultGlobalConfigPath(envConfig["prefix"]);
107
+ const userConfigPath = envConfig["userconfig"] ?? path.join(os.homedir(), ".npmrc");
108
+ const projectConfigPath = await findNearestProjectNpmrc(startDir);
109
+ const [globalConfig, userConfig, projectConfig] = await Promise.all([
110
+ await readNpmrc(globalConfigPath),
111
+ await readNpmrc(userConfigPath),
112
+ await readNpmrc(projectConfigPath)
113
+ ]);
114
+ return {
115
+ builtin: {
116
+ registry: defaultNpmRegistry
117
+ },
118
+ global: globalConfig,
119
+ user: userConfig,
120
+ project: projectConfig,
121
+ env: envConfig,
122
+ paths: {
123
+ project: projectConfigPath,
124
+ user: userConfigPath,
125
+ global: globalConfigPath
126
+ }
127
+ };
128
+ }
129
+ //# sourceMappingURL=resolveNpmrcConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveNpmrcConfig.js","sourceRoot":"","sources":["../../../src/cli/utils/resolveNpmrcConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAC,WAAW,EAAC,MAAM,qCAAqC,CAAC;AAEhE,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACvC,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEvD,MAAM,YAAY,GAA2B;QACzC,GAAG,MAAM,CAAC,OAAO;QACjB,GAAG,MAAM,CAAC,MAAM;QAChB,GAAG,MAAM,CAAC,IAAI;QACd,GAAG,MAAM,CAAC,OAAO;QACjB,GAAG,MAAM,CAAC,GAAG;KAChB,CAAC;IAEF,OAAO,YAAY,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,WAAmC;IAChE,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,IAAI,kBAAkB,CAAC;IAC/D,IAAI,gBAAgB,GAAW,WAAW,CAAC;IAE3C,IAAI,CAAC;QACD,MAAM,GAAG,G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AE,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IACpF,MAAM,iBAAiB,GAAG,MAAM,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAElE,MAAM,CACF,YAAY,EACZ,UAAU,EACV,aAAa,CAChB,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAClB,MAAM,SAAS,CAAC,gBAAgB,CAAC;QACjC,MAAM,SAAS,CAAC,cAAc,CAAC;QAC/B,MAAM,SAAS,CAAC,iBAAiB,CAAC;KACrC,CAAC,CAAC;IAEH,OAAO;QACH,OAAO,EAAE;YACL,QAAQ,EAAE,kBAAkB;SAC/B;QACD,MAAM,EAAE,YAAY;QACpB,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,aAAa;QACtB,GAAG,EAAE,SAAS;QACd,KAAK,EAAE;YACH,OAAO,EAAE,iBAAiB;YAC1B,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,gBAAgB;SAC3B;KACJ,CAAC;AACN,CAAC"}
package/dist/config.d.ts CHANGED
@@ -5,11 +5,13 @@ export declare const llamaPrebuiltBinsDirectory: string;
5
5
  export declare const llamaLocalBuildBinsDirectory: string;
6
6
  export declare const llamaBinsGrammarsDirectory: string;
7
7
  export declare const projectTemplatesDirectory: string;
8
+ export declare const localTempDirectory: string;
8
9
  export declare const packedProjectTemplatesDirectory: string;
9
10
  export declare const llamaCppDirectory: string;
10
11
  export declare const llamaCppGrammarsDirectory: string;
11
12
  export declare const tempDownloadDirectory: string;
12
13
  export declare const cliHomedirDirectory: string;
14
+ export declare const cliHomedirTempDirectory: string;
13
15
  export declare const chatCommandHistoryFilePath: string;
14
16
  export declare const cliModelsDirectory: string;
15
17
  export declare const lastBuildInfoJsonPath: string;
@@ -28,10 +30,11 @@ export declare const isRunningInsideGoogleColab: boolean;
28
30
  export declare const useCiLogs: boolean;
29
31
  export declare const defaultLlamaCppGitHubRepo: string;
30
32
  export declare const defaultLlamaCppRelease: string;
31
- export declare const defaultLlamaCppGpuSupport: false | "metal" | "cuda" | "vulkan" | "auto";
33
+ export declare const defaultLlamaCppGpuSupport: false | "auto" | "metal" | "cuda" | "vulkan";
32
34
  export declare const defaultLlamaCppLogLevel: LlamaLogLevel;
33
35
  export declare const defaultLlamaCppDebugMode: boolean;
34
36
  export declare const defaultSkipDownload: boolean;
37
+ export declare const defaultNodeLlamaCppPostinstall: "auto" | "ignoreFailedBuild" | "skip";
35
38
  export declare const defaultBindingTestLogLevel: LlamaLogLevel;
36
39
  export declare const defaultXpacksStoreDirectory: string;
37
40
  export declare const defaultXpacksCacheDirectory: string;
@@ -43,6 +46,7 @@ export declare const enableRecursiveClone = false;
43
46
  export declare const documentationPageUrls: {
44
47
  readonly CUDA: string;
45
48
  readonly Vulkan: string;
49
+ readonly BuildingFromSource: string;
46
50
  readonly CLI: {
47
51
  readonly index: string;
48
52
  readonly Pull: string;
@@ -66,6 +70,7 @@ export declare const documentationPageUrls: {
66
70
  };
67
71
  readonly troubleshooting: {
68
72
  readonly RosettaIllegalHardwareInstruction: string;
73
+ readonly PostinstallBehavior: string;
69
74
  };
70
75
  };
71
76
  export declare const newGithubIssueUrl = "https://github.com/withcatai/node-llama-cpp/issues";
package/dist/config.js CHANGED
@@ -14,11 +14,13 @@ export const llamaPrebuiltBinsDirectory = path.join(__dirname, "..", "bins");
14
14
  export const llamaLocalBuildBinsDirectory = path.join(llamaDirectory, "localBuilds");
15
15
  export const llamaBinsGrammarsDirectory = path.join(__dirname, "..", "llama", "grammars");
16
16
  export const projectTemplatesDirectory = path.join(__dirname, "..", "templates");
17
+ export const localTempDirectory = path.join(__dirname, "..", ".temp");
17
18
  export const packedProjectTemplatesDirectory = path.join(projectTemplatesDirectory, "packed");
18
19
  export const llamaCppDirectory = path.join(llamaDirectory, "llama.cpp");
19
20
  export const llamaCppGrammarsDirectory = path.join(llamaDirectory, "llama.cpp", "grammars");
20
21
  export const tempDownloadDirectory = path.join(os.tmpdir(), "node-llama-cpp", nanoid());
21
22
  export const cliHomedirDirectory = path.join(os.homedir(), ".node-llama-cpp");
23
+ export const cliHomedirTempDirectory = path.join(os.homedir(), ".node-llama-cpp", ".temp");
22
24
  export const chatCommandHistoryFilePath = path.join(cliHomedirDirectory, ".chat_repl_history");
23
25
  export const cliModelsDirectory = path.join(cliHomedirDirectory, "models");
24
26
  export const lastBuildInfoJsonPath = path.join(llamaDirectory, "lastBuild.json");
@@ -60,6 +62,12 @@ export const defaultLlamaCppDebugMode = env.get("NODE_LLAMA_CPP_DEBUG")
60
62
  export const defaultSkipDownload = env.get("NODE_LLAMA_CPP_SKIP_DOWNLOAD")
61
63
  .default("false")
62
64
  .asBool();
65
+ // set via a `--node-llama-cpp-postinstall=ignoreFailedBuild` flag on an `npm install` command
66
+ export const defaultNodeLlamaCppPostinstall = env.get("NODE_LLAMA_CPP_POSTINSTALL")
67
+ .default(env.get("npm_config_node_llama_cpp_postinstall")
68
+ .default("auto")
69
+ .asEnum(["auto", "ignoreFailedBuild", "skip"]))
70
+ .asEnum(["auto", "ignoreFailedBuild", "skip"]);
63
71
  export const defaultBindingTestLogLevel = env.get("NODE_LLAMA_CPP_BINDING_TEST_LOG_LEVEL")
64
72
  .default(LlamaLogLevel.error)
65
73
  .asEnum(LlamaLogLevelValues);
@@ -84,7 +92,8 @@ const documentationUrl = "https://node-llama-cpp.withcat.ai";
84
92
  const documentationCliUrl = documentationUrl + "/cli";
85
93
  export const documentationPageUrls = {
86
94
  CUDA: documentationUrl + "/guide/CUDA",
87
- Vulkan: documentationUrl + "/guide/vulkan",
95
+ Vulkan: documentationUrl + "/guide/Vulkan",
96
+ BuildingFromSource: documentationUrl + "/guide/building-from-source",
88
97
  CLI: {
89
98
  index: documentationCliUrl,
90
99
  Pull: documentationCliUrl + "/pull",
@@ -107,7 +116,8 @@ export const documentationPageUrls = {
107
116
  }
108
117
  },
109
118
  troubleshooting: {
110
- RosettaIllegalHardwareInstruction: documentationUrl + "/guide/troubleshooting#illegal-hardware-instruction"
119
+ RosettaIllegalHardwareInstruction: documentationUrl + "/guide/troubleshooting#illegal-hardware-instruction",
120
+ PostinstallBehavior: documentationUrl + "/guide/troubleshooting#postinstall-behavior"
111
121
  }
112
122
  };
113
123
  export const newGithubIssueUrl = "https://github.com/withcatai/node-llama-cpp/issues";
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,wBAAwB,EAAC,MAAM,2CAA2C,CAAC;AACnF,OAAO,EACH,sBAAsB,EAAE,aAAa,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,+BAA+B,EAC1H,MAAM,qBAAqB,CAAC;AAE7B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAGrC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,aAAa,CA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E,mBAAmB,GAAG,OAAO;QACnC,QAAQ,EAAE,mBAAmB,GAAG,WAAW;QAC3C,MAAM,EAAE,mBAAmB,GAAG,SAAS;QACvC,OAAO,EAAE;YACL,KAAK,EAAE,mBAAmB,GAAG,UAAU;YACvC,GAAG,EAAE,mBAAmB,GAAG,cAAc;YACzC,IAAI,EAAE,mBAAmB,GAAG,eAAe;YAC3C,OAAO,EAAE,mBAAmB,GAAG,kBAAkB;YACjD,QAAQ,EAAE,mBAAmB,GAAG,mBAAmB;SACtD;QACD,MAAM,EAAE;YACJ,KAAK,EAAE,mBAAmB,GAAG,SAAS;YACtC,QAAQ,EAAE,mBAAmB,GAAG,kBAAkB;YAClD,KAAK,EAAE,mBAAmB,GAAG,eAAe;YAC5C,KAAK,EAAE,mBAAmB,GAAG,eAAe;SAC/C;KACJ;IACD,eAAe,EAAE;QACb,iCAAiC,EAAE,gBAAgB,GAAG,qDAAqD;QAC3G,mBAAmB,EAAE,gBAAgB,GAAG,6CAA6C;KACxF;CACK,CAAC;AACX,MAAM,CAAC,MAAM,iBAAiB,GAAG,oDAAoD,CAAC;AACtF,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,CAAC;AACpD,MAAM,CAAC,MAAM,mCAAmC,GAAG,EAAE,CAAC;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC,CAAC,oFAAoF"}
@@ -290,13 +290,19 @@ export type LLamaChatGenerateResponseOptions<Functions extends ChatModelFunction
290
290
  /**
291
291
  * Budget for thought tokens.
292
292
  *
293
- * Defaults to `Infinity`.
293
+ * Set to `Infinity` for unlimited budget.
294
+ *
295
+ * Defaults to 75% of the context size.
296
+ * When the context size is smaller than `8192`, defaults to 50% of the context size.
294
297
  */
295
298
  thoughtTokens?: number;
296
299
  /**
297
300
  * Budget for comment tokens.
298
301
  *
299
- * Defaults to `Infinity`.
302
+ * Set to `Infinity` for unlimited budget.
303
+ *
304
+ * Defaults to 75% of the context size.
305
+ * When the context size is smaller than `8192`, defaults to 50% of the context size.
300
306
  */
301
307
  commentTokens?: number;
302
308
  };
@@ -1,4 +1,5 @@
1
1
  import { DisposeAggregator, DisposedError, EventRelay, withLock } from "lifecycle-utils";
2
+ import { internalCheckpoints } from "../LlamaContext/LlamaContext.js";
2
3
  import { isChatModelResponseFunctionCall, isChatModelResponseSegment, allSegmentTypes } from "../../types.js";
3
4
  import { removeNullFields } from "../../utils/removeNullFields.js";
4
5
  import { LlamaGrammarEvaluationState } from "../LlamaGrammarEvaluationState.js";
@@ -15,6 +16,7 @@ import { LlamaSampler } from "../LlamaContext/LlamaSampler.js";
15
16
  import { getChatWrapperSegmentDefinition } from "../../utils/getChatWrapperSegmentDefinition.js";
16
17
  import { jsonDumps } from "../../chatWrappers/utils/jsonDumps.js";
17
18
  import { defaultMaxPreloadTokens } from "../LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js";
19
+ import { LlamaLogLevel } from "../../bindings/types.js";
18
20
  import { eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy } from "./utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js";
19
21
  import { FunctionCallNameGrammar } from "./utils/FunctionCallNameGrammar.js";
20
22
  import { FunctionCallParamsGrammar } from "./utils/FunctionCallParamsGrammar.js";
@@ -26,6 +28,9 @@ const defaultContextShiftOptions = {
26
28
  const defaultRepeatPenaltyLastTokens = 64;
27
29
  const defaultTrimWhitespaceSuffix = false;
28
30
  const defaultEvaluationPriority = 5;
31
+ const defaultSegmentBudgetSize = (contextSize) => (contextSize < 8192
32
+ ? contextSize * 0.5
33
+ : contextSize * 0.75);
29
34
  export class LlamaChat {
30
35
  /** @internal */ _chatWrapper;
31
36
  /** @internal */ _disposeAggregator = new DisposeAggregator();
@@ -118,7 +123,9 @@ export class LlamaChat {
118
123
  if (generateResponseState.grammar != null && generateResponseState.functionsEnabled && !abortOnNonText)
119
124
  throw new Error("Using both grammar and functions is not supported yet");
120
125
  return await withLock([this._chatLock, "evaluate"], signal, async () => {
126
+ let hadError = false;
121
127
  try {
128
+ let tookInitialCheckpoint = false;
122
129
  generateResponseState.ensureLastHistoryItemIsModel();
123
130
  generateResponseState.ensureReopenedThoughtSegmentAfterFunctionCallsIfNeeded();
124
131
  const loadContextWindow = async (avoidReloadingHistory = false) => {
@@ -156,6 +163,10 @@ export class LlamaChat {
156
163
  await generateResponseState.alignCurrentSequenceStateWithCurrentTokens();
157
164
  await generateResponseState.createNewEvaluationIterator();
158
165
  while (await generateResponseState.iterateEvaluation()) {
166
+ if (!tookInitialCheckpoint && this.sequence.needsCheckpoints) {
167
+ await this.sequence.takeCheckpoint();
168
+ tookInitialCheckpoint = true;
169
+ }
159
170
  if (!generateResponseState.holdPartialTokensForNextEvaluation()) {
160
171
  generateResponseState.waitOnPartialCharactersOrWhiteSpaceTokens();
161
172
  generateResponseState.detectAndHandleFunctionStartSyntax();
@@ -166,7 +177,11 @@ export class LlamaChat {
166
177
  if (functionsCallsRes != null)
167
178
  return functionsCallsRes;
168
179
  }
169
- generateResponseState.recordStopGenerationEvaluation();
180
+ {
181
+ const resPromise = generateResponseState.recordStopGenerationEvaluation();
182
+ if (resPromise instanceof Promise)
183
+ await resPromise;
184
+ }
170
185
  generateResponseState.popStreamRegulatorFreeTokens();
171
186
  generateResponseState.removeFoundStartIgnoreTextsFromPendingTokens();
172
187
  const stopGenerationTriggerRes = generateResponseState.handleStopGenerationTrigger("model");
@@ -198,8 +213,14 @@ export class LlamaChat {
198
213
  }
199
214
  throw new Error("The context size is too small to generate a response");
200
215
  }
216
+ catch (err) {
217
+ hadError = true;
218
+ throw err;
219
+ }
201
220
  finally {
202
221
  await generateResponseState.dispose();
222
+ if (!hadError && this.sequence.needsCheckpoints)
223
+ void this.sequence.takeCheckpoint();
203
224
  }
204
225
  });
205
226
  }
@@ -247,6 +268,7 @@ export class LlamaChat {
247
268
  });
248
269
  return await withLock([this._chatLock, "evaluate"], signal, async () => {
249
270
  try {
271
+ let tookInitialCheckpoint = false;
250
272
  generateResponseState.ensureLastHistoryItemIsUser();
251
273
  while (true) {
252
274
  generateResponseState.startTokenLoop();
@@ -279,9 +301,17 @@ export class LlamaChat {
279
301
  }
280
302
  await generateResponseState.createNewEvaluationIterator();
281
303
  while (await generateResponseState.iterateEvaluation()) {
304
+ if (!tookInitialCheckpoint && this.sequence.needsCheckpoints) {
305
+ await this.sequence.takeCheckpoint();
306
+ tookInitialCheckpoint = true;
307
+ }
282
308
  if (!generateResponseState.holdPartialTokensForNextEvaluation()) {
283
309
  generateResponseState.waitOnPartialCharactersOrWhiteSpaceTokens();
284
- generateResponseState.recordStopGenerationEvaluation();
310
+ {
311
+ const resPromise = generateResponseState.recordStopGenerationEvaluation();
312
+ if (resPromise instanceof Promise)
313
+ await resPromise;
314
+ }
285
315
  generateResponseState.popStreamRegulatorFreeTokens();
286
316
  const someOfCurrentTokensAreSpecial = generateResponseState.currentTokens.some((token) => (this.model.isSpecialToken(token)));
287
317
  const stopGenerationTriggerRes = generateResponseState.handleStopGenerationTrigger("user", someOfCurrentTokensAreSpecial
@@ -792,6 +822,7 @@ class GenerateResponseState {
792
822
  userTextSuffix = undefined;
793
823
  prefixTriggerDetectors = new Map();
794
824
  noPrefixTrigger = undefined;
825
+ responsePrefix = undefined;
795
826
  rerenderTriggers = [];
796
827
  rerenderTriggerDetector = new StopGenerationDetector();
797
828
  rerenderActions = undefined;
@@ -1148,6 +1179,9 @@ class GenerateResponseState {
1148
1179
  !this.segmentHandler.isSegmentTypeOpen(trigger.segmentType) &&
1149
1180
  this.segmentHandler.getSegmentTokensCount(trigger.segmentType) >= segmentBudget)
1150
1181
  continue;
1182
+ if (this.responsePrefix == null && trigger.type === "response" && trigger.triggers.length > 0 &&
1183
+ (trigger.triggers[0]?.values?.length ?? 0) > 0)
1184
+ this.responsePrefix = LlamaText([trigger.triggers[0] ?? "", trigger.inject ?? ""]);
1151
1185
  const prefixDetector = new StopGenerationDetector();
1152
1186
  StopGenerationDetector.resolveStopTriggers(trigger.triggers, this.llamaChat.model.tokenizer)
1153
1187
  .forEach((stopTrigger) => prefixDetector.addStopTrigger(stopTrigger));
@@ -1172,6 +1206,8 @@ class GenerateResponseState {
1172
1206
  !this.segmentHandler.isSegmentTypeOpen(noPrefixTrigger.segmentType) &&
1173
1207
  this.segmentHandler.getSegmentTokensCount(noPrefixTrigger.segmentType) >= noPrefixTriggerSegmentBudget)
1174
1208
  this.noPrefixTrigger = undefined;
1209
+ else if (noPrefixTrigger?.type === "response")
1210
+ this.responsePrefix = noPrefixTrigger.inject;
1175
1211
  this.rerenderTriggers = rerender?.triggers ?? [];
1176
1212
  this.rerenderTriggerDetector.clearInProgressStops();
1177
1213
  this.rerenderTriggerDetector.clearTriggeredStops();
@@ -1252,6 +1288,11 @@ class GenerateResponseState {
1252
1288
  if (alignStateTokens)
1253
1289
  await reloadTokens();
1254
1290
  };
1291
+ if (this.grammar != null) {
1292
+ if (this.responsePrefix != null)
1293
+ await injectTokens(this.responsePrefix, true);
1294
+ return undefined;
1295
+ }
1255
1296
  if (this.prefixTriggerDetectors.size === 0) {
1256
1297
  if (this.abortOnNonText && this.noPrefixTrigger != null && this.noPrefixTrigger.type !== "response") {
1257
1298
  this.shouldAbortBecauseOfNonText = true;
@@ -1275,7 +1316,12 @@ class GenerateResponseState {
1275
1316
  const generatedTokens = [];
1276
1317
  let isFirstToken = true;
1277
1318
  let continueGeneration = true;
1319
+ let tookInitialCheckpoint = false;
1278
1320
  for await (const tokens of this.evaluateWithContextShift(loadContextWindow)) {
1321
+ if (!tookInitialCheckpoint && this.llamaChat.sequence.needsCheckpoints) {
1322
+ await this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatSequenceStart.name, internalCheckpoints.chatSequenceStart.maxCheckpoints);
1323
+ tookInitialCheckpoint = true;
1324
+ }
1279
1325
  pushAll(generatedTokens, tokens);
1280
1326
  for (const [triggerDetector, { trigger, inject }] of [...this.prefixTriggerDetectors.entries()]) {
1281
1327
  triggerDetector.recordGeneration({
@@ -1420,7 +1466,12 @@ class GenerateResponseState {
1420
1466
  pushAll(prefixDetectorRecordedTokens, tokens);
1421
1467
  }
1422
1468
  }
1469
+ let tookInitialCheckpoint = false;
1423
1470
  for await (const tokens of this.evaluateWithContextShift(loadContextWindow)) {
1471
+ if (!tookInitialCheckpoint && this.llamaChat.sequence.needsCheckpoints) {
1472
+ await this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatSequenceStart.name, internalCheckpoints.chatSequenceStart.maxCheckpoints);
1473
+ tookInitialCheckpoint = true;
1474
+ }
1424
1475
  const stopGenerationTriggerRes = this.handleStopGenerationTrigger("model");
1425
1476
  if (stopGenerationTriggerRes != null)
1426
1477
  return stopGenerationTriggerRes;
@@ -1463,7 +1514,11 @@ class GenerateResponseState {
1463
1514
  tokens: this.currentTokens,
1464
1515
  text: this.currentText
1465
1516
  });
1466
- this.recordStopGenerationEvaluation();
1517
+ {
1518
+ const resPromise = this.recordStopGenerationEvaluation();
1519
+ if (resPromise instanceof Promise)
1520
+ await resPromise;
1521
+ }
1467
1522
  }
1468
1523
  this.currentFunctionCallCurrentPartTokens.length = 0;
1469
1524
  this.functionEvaluationMode = false;
@@ -1515,7 +1570,12 @@ class GenerateResponseState {
1515
1570
  }
1516
1571
  }
1517
1572
  }
1573
+ let tookInitialCheckpoint = false;
1518
1574
  for await (const tokens of this.evaluateWithContextShift(loadContextWindow)) {
1575
+ if (!tookInitialCheckpoint && this.llamaChat.sequence.needsCheckpoints) {
1576
+ await this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatSequenceStart.name, internalCheckpoints.chatSequenceStart.maxCheckpoints);
1577
+ tookInitialCheckpoint = true;
1578
+ }
1519
1579
  pushAll(this.currentFunctionCallCurrentPartTokens, tokens);
1520
1580
  functionNameGenerationDoneDetector.recordGeneration({
1521
1581
  text: this.currentText,
@@ -1578,11 +1638,20 @@ class GenerateResponseState {
1578
1638
  paramsChunk: this.llamaChat.model.detokenize(this.currentFunctionCallCurrentPartTokens, false, lastPartTokens),
1579
1639
  done: false
1580
1640
  });
1641
+ let tookInitialCheckpoint = false;
1581
1642
  for await (const tokens of this.evaluateWithContextShift(loadContextWindow)) {
1643
+ if (!tookInitialCheckpoint && this.llamaChat.sequence.needsCheckpoints) {
1644
+ await this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatSequenceStart.name, internalCheckpoints.chatSequenceStart.maxCheckpoints);
1645
+ tookInitialCheckpoint = true;
1646
+ }
1647
+ const hadInProgressTriggers = functionParamsGenerationDoneDetector.hasInProgressStops;
1582
1648
  functionParamsGenerationDoneDetector.recordGeneration({
1583
1649
  text: this.currentText,
1584
1650
  tokens: this.currentTokens
1585
1651
  });
1652
+ if (!hadInProgressTriggers && functionParamsGenerationDoneDetector.hasInProgressStops &&
1653
+ this.llamaChat.sequence.needsCheckpoints)
1654
+ await this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatGrammarEnd.name, internalCheckpoints.chatGrammarEnd.maxCheckpoints);
1586
1655
  this.onFunctionCallParamsChunk?.({
1587
1656
  callIndex: this.resFunctionCalls.length,
1588
1657
  functionName: this.functionEvaluationFunctionName,
@@ -1646,7 +1715,12 @@ class GenerateResponseState {
1646
1715
  LlamaText(new SpecialToken("EOT"))
1647
1716
  ], this.llamaChat.model.tokenizer)
1648
1717
  .map((stopTrigger) => sectionSuffixDetector.addStopTrigger(stopTrigger));
1718
+ let tookInitialCheckpoint = false;
1649
1719
  for await (const tokens of this.evaluateWithContextShift(loadContextWindow)) {
1720
+ if (!tookInitialCheckpoint && this.llamaChat.sequence.needsCheckpoints) {
1721
+ await this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatSequenceStart.name, internalCheckpoints.chatSequenceStart.maxCheckpoints);
1722
+ tookInitialCheckpoint = true;
1723
+ }
1650
1724
  pushAll(this.currentFunctionCallCurrentPartTokens, tokens);
1651
1725
  sectionSuffixDetector.recordGeneration({
1652
1726
  text: this.currentText,
@@ -1772,6 +1846,19 @@ class GenerateResponseState {
1772
1846
  }));
1773
1847
  }
1774
1848
  async createNewEvaluationIterator() {
1849
+ if (this.tokens.length === 0) {
1850
+ if (this.evaluationIterator != null)
1851
+ return;
1852
+ const token = this.llamaChat.sequence.contextTokens.at(-1);
1853
+ if (token == null)
1854
+ throw new Error("No tokens to evaluate");
1855
+ this.llamaChat.sequence.model._llama._log(LlamaLogLevel.warn, "Attempted to evaluate with no input, reevaluating the last context sequence token");
1856
+ await this.llamaChat.sequence.eraseContextTokenRanges([{
1857
+ start: this.llamaChat.sequence.contextTokens.length - 1,
1858
+ end: this.llamaChat.sequence.contextTokens.length
1859
+ }]);
1860
+ this.tokens = [token];
1861
+ }
1775
1862
  if (this.evaluationIterator != null)
1776
1863
  await this.evaluationIterator.return();
1777
1864
  this.currentIterationReplacementToken = undefined;
@@ -1881,6 +1968,7 @@ class GenerateResponseState {
1881
1968
  }
1882
1969
  }
1883
1970
  recordStopGenerationEvaluation() {
1971
+ const hadInProgressStopTrigger = this.stopGenerationDetector.hasInProgressStops;
1884
1972
  this.rerenderTriggerDetector.recordGeneration({
1885
1973
  text: this.currentText,
1886
1974
  tokens: this.currentTokens,
@@ -1898,6 +1986,9 @@ class GenerateResponseState {
1898
1986
  });
1899
1987
  if (this.llamaChat.model.isEogToken(this.currentToken))
1900
1988
  this.currentQueuedTokenRelease?.createTokenIndexLock(0);
1989
+ if (this.grammar != null && !hadInProgressStopTrigger && this.stopGenerationDetector.hasInProgressStops &&
1990
+ this.llamaChat.sequence.needsCheckpoints)
1991
+ return this.llamaChat.sequence._takeNamedCheckpoint(internalCheckpoints.chatGrammarEnd.name, internalCheckpoints.chatGrammarEnd.maxCheckpoints);
1901
1992
  }
1902
1993
  popStreamRegulatorFreeTokens() {
1903
1994
  pushAll(this.pendingTokens, this.streamRegulator.popFreeChunkTokens());
@@ -2020,9 +2111,11 @@ class GenerateResponseState {
2020
2111
  return shouldReloadEvaluationState;
2021
2112
  }
2022
2113
  getSegmentBudget(segmentType) {
2023
- const getBudget = (budget) => ((budget == null || budget === Infinity)
2024
- ? null
2025
- : budget);
2114
+ const getBudget = (budget) => (budget == null
2115
+ ? Math.ceil(defaultSegmentBudgetSize(this.llamaChat.sequence.contextSize))
2116
+ : budget === Infinity
2117
+ ? null
2118
+ : budget);
2026
2119
  if (this.budgets == null)
2027
2120
  return null;
2028
2121
  if (segmentType === "thought")