@realtimex/node-llama-cpp-win-x64-cuda-ext 0.0.0-bootstrap.0 → 0.0.0-cuda-ext-test.34.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Gilad S.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- # @realtimex/node-llama-cpp-win-x64-cuda-ext
1
+ # [`node-llama-cpp`](https://github.com/withcatai/node-llama-cpp)
2
+ This is an extension of the [`@realtimex/win-x64-cuda`](https://www.npmjs.com/package/@realtimex/win-x64-cuda) package
3
+ that provides a prebuilt binary for [`node-llama-cpp`](https://github.com/withcatai/node-llama-cpp) for Windows x64 with CUDA support.
2
4
 
3
- Bootstrap placeholder package used to reserve this package name and configure npm Trusted Publisher for CI/CD.
4
-
5
- This version does not contain runtime binaries.
5
+ Do not install this package directly.
@@ -0,0 +1,45 @@
1
+ {
2
+ "version": 1,
3
+ "folderName": "win-x64-cuda",
4
+ "fallbackBinaryName": "ggml-cuda.dll",
5
+ "finalSize": 509153280,
6
+ "sha256": "25b1dad3ed3aa896d16bbc847c68ffeac4073154f8cf0c4b0e06e805bec046e3",
7
+ "chunks": [
8
+ {
9
+ "packageName": "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-01",
10
+ "fileName": "win-x64-cuda.part-01.bin",
11
+ "size": 100663296,
12
+ "sha256": "e5c500da4c1aa96c27c26ea2c8a70a0af4308b3841380ed8c653a9658c8d71d5"
13
+ },
14
+ {
15
+ "packageName": "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-02",
16
+ "fileName": "win-x64-cuda.part-02.bin",
17
+ "size": 100663296,
18
+ "sha256": "99d0a8d5c5f39d686c062a827c28ef4deccd3f734711a3cdfcb9d476efa99e34"
19
+ },
20
+ {
21
+ "packageName": "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-03",
22
+ "fileName": "win-x64-cuda.part-03.bin",
23
+ "size": 100663296,
24
+ "sha256": "260d19b121b254b9369f52cdcb0c318cbfa0d1daa972cfd8908f6841de67baa5"
25
+ },
26
+ {
27
+ "packageName": "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-04",
28
+ "fileName": "win-x64-cuda.part-04.bin",
29
+ "size": 100663296,
30
+ "sha256": "5e0ce86746f9f49bc470b5da3e5ed6d2dc4c23e31fb952e2a526c784001dd73c"
31
+ },
32
+ {
33
+ "packageName": "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-05",
34
+ "fileName": "win-x64-cuda.part-05.bin",
35
+ "size": 100663296,
36
+ "sha256": "e186ac211ee2cdcff13d80d214bf1063b56bba5026e7e0c2127665be9dc67973"
37
+ },
38
+ {
39
+ "packageName": "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-06",
40
+ "fileName": "win-x64-cuda.part-06.bin",
41
+ "size": 5836800,
42
+ "sha256": "270aa3da23babd6c11dba5254202036c92e30b8b174428a2c2e1774857ee47d7"
43
+ }
44
+ ]
45
+ }
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ import path from "path";
2
+ import { fileURLToPath } from "url";
3
+ import fs from "node:fs";
4
+ import { createHash } from "node:crypto";
5
+ import { createRequire } from "node:module";
6
+ const require = createRequire(import.meta.url);
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ const packageRoot = path.join(__dirname, "..");
9
+ const binsDir = path.join(packageRoot, "bins");
10
+ const packageVersion = JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8")).version;
11
+ const chunkManifestPath = path.join(packageRoot, "chunk-manifest.json");
12
+ export function getBinsDir() {
13
+ ensureAssembledFallbackBinary();
14
+ return {
15
+ binsDir,
16
+ packageVersion
17
+ };
18
+ }
19
+ function ensureAssembledFallbackBinary() {
20
+ const chunkManifest = readChunkManifest();
21
+ if (chunkManifest == null)
22
+ return;
23
+ const fallbackBinaryPath = path.join(binsDir, chunkManifest.folderName, "fallback", chunkManifest.fallbackBinaryName);
24
+ if (fs.existsSync(fallbackBinaryPath) && fs.statSync(fallbackBinaryPath).size === chunkManifest.finalSize)
25
+ return;
26
+ const tempFallbackBinaryPath = fallbackBinaryPath + `.${process.pid}.assemble`;
27
+ const tempDir = path.dirname(tempFallbackBinaryPath);
28
+ fs.mkdirSync(tempDir, { recursive: true });
29
+ fs.rmSync(tempFallbackBinaryPath, { force: true });
30
+ fs.rmSync(fallbackBinaryPath, { force: true });
31
+ const outputFd = fs.openSync(tempFallbackBinaryPath, "w");
32
+ const hash = createHash("sha256");
33
+ let totalSize = 0;
34
+ try {
35
+ for (const chunk of chunkManifest.chunks) {
36
+ const chunkPackageJsonPath = require.resolve(`${chunk.packageName}/package.json`);
37
+ const chunkPackageRoot = path.dirname(chunkPackageJsonPath);
38
+ const chunkFilePath = path.join(chunkPackageRoot, "chunks", chunk.fileName);
39
+ const chunkContents = fs.readFileSync(chunkFilePath);
40
+ if (chunkContents.byteLength !== chunk.size)
41
+ throw new Error(`Chunk "${chunk.packageName}" has unexpected size`);
42
+ const chunkSha256 = createHash("sha256")
43
+ .update(chunkContents)
44
+ .digest("hex");
45
+ if (chunkSha256 !== chunk.sha256)
46
+ throw new Error(`Chunk "${chunk.packageName}" has unexpected SHA-256`);
47
+ fs.writeSync(outputFd, chunkContents);
48
+ hash.update(chunkContents);
49
+ totalSize += chunkContents.byteLength;
50
+ }
51
+ }
52
+ finally {
53
+ fs.closeSync(outputFd);
54
+ }
55
+ if (totalSize !== chunkManifest.finalSize) {
56
+ cleanupFailedAssembly(tempFallbackBinaryPath);
57
+ throw new Error("Assembled CUDA fallback backend has unexpected size");
58
+ }
59
+ const assembledSha256 = hash.digest("hex");
60
+ if (assembledSha256 !== chunkManifest.sha256) {
61
+ cleanupFailedAssembly(tempFallbackBinaryPath);
62
+ throw new Error("Assembled CUDA fallback backend has unexpected SHA-256");
63
+ }
64
+ fs.renameSync(tempFallbackBinaryPath, fallbackBinaryPath);
65
+ }
66
+ function readChunkManifest() {
67
+ if (!fs.existsSync(chunkManifestPath))
68
+ return null;
69
+ return JSON.parse(fs.readFileSync(chunkManifestPath, "utf8"));
70
+ }
71
+ if (process.argv[1] != null &&
72
+ path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) &&
73
+ process.argv.includes("--assemble")) {
74
+ ensureAssembledFallbackBinary();
75
+ }
76
+ function cleanupFailedAssembly(tempFallbackBinaryPath) {
77
+ fs.rmSync(tempFallbackBinaryPath, { force: true });
78
+ }
package/package.json CHANGED
@@ -1,18 +1,55 @@
1
1
  {
2
2
  "name": "@realtimex/node-llama-cpp-win-x64-cuda-ext",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Bootstrap placeholder used to reserve this package name and configure npm Trusted Publisher for CI/CD.",
5
- "main": "./index.js",
3
+ "version": "0.0.0-cuda-ext-test.34.1",
4
+ "description": "Extension of @realtimex/win-x64-cuda - prebuilt binary for node-llama-cpp for Windows x64 with CUDA support",
5
+ "main": "dist/index.js",
6
+ "type": "module",
6
7
  "files": [
7
- "index.js",
8
- "README.md"
8
+ "dist/",
9
+ "chunk-manifest.json",
10
+ "package.json",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "node": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "engines": {
22
+ "node": ">=20.0.0"
23
+ },
24
+ "os": [
25
+ "win32"
26
+ ],
27
+ "cpu": [
28
+ "x64"
9
29
  ],
10
- "license": "MIT",
11
30
  "repository": {
12
31
  "type": "git",
13
32
  "url": "git+https://github.com/therealtimex/node-llama-cpp.git"
14
33
  },
34
+ "author": "Gilad S.",
35
+ "license": "MIT",
36
+ "preferUnplugged": true,
37
+ "bugs": {
38
+ "url": "https://github.com/therealtimex/node-llama-cpp/issues"
39
+ },
40
+ "homepage": "https://node-llama-cpp.withcat.ai",
15
41
  "publishConfig": {
16
42
  "access": "public"
43
+ },
44
+ "scripts": {
45
+ "postinstall": "node ./dist/index.js --assemble"
46
+ },
47
+ "dependencies": {
48
+ "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-01": "0.0.0-cuda-ext-test.34.1",
49
+ "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-02": "0.0.0-cuda-ext-test.34.1",
50
+ "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-03": "0.0.0-cuda-ext-test.34.1",
51
+ "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-04": "0.0.0-cuda-ext-test.34.1",
52
+ "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-05": "0.0.0-cuda-ext-test.34.1",
53
+ "@realtimex/node-llama-cpp-win-x64-cuda-ext-chunk-06": "0.0.0-cuda-ext-test.34.1"
17
54
  }
18
55
  }
package/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- function getBinsDir() {
4
- throw new Error("This is a bootstrap placeholder package. No runtime binaries have been published for this package version.");
5
- }
6
-
7
- module.exports = {
8
- getBinsDir
9
- };