@fugood/llama.node 0.0.1-alpha.3 → 0.0.1-alpha.4

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.
Binary file
Binary file
Binary file
Binary file
package/lib/binding.js CHANGED
@@ -33,13 +33,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.loadModule = void 0;
36
+ const path = __importStar(require("path"));
37
+ const setupEnv = (variant) => {
38
+ var _a, _b;
39
+ const postfix = variant ? `-${variant}` : '';
40
+ const binPath = path.resolve(__dirname, `../bin/${process.platform}${postfix}/${process.arch}/`);
41
+ const systemPathEnv = (_b = (_a = process.env.PATH) !== null && _a !== void 0 ? _a : process.env.Path) !== null && _b !== void 0 ? _b : '';
42
+ if (!systemPathEnv.includes(binPath)) {
43
+ if (process.platform === 'win32') {
44
+ process.env.Path = `${binPath};${systemPathEnv}`;
45
+ }
46
+ else {
47
+ process.env.PATH = `${binPath}:${systemPathEnv}`;
48
+ }
49
+ }
50
+ };
36
51
  const loadModule = (variant) => __awaiter(void 0, void 0, void 0, function* () {
37
52
  try {
38
53
  if (variant) {
54
+ setupEnv(variant);
39
55
  return yield Promise.resolve(`${`../bin/${process.platform}-${variant}/${process.arch}/llama-node.node`}`).then(s => __importStar(require(s)));
40
56
  }
41
57
  }
42
58
  catch (_a) { } // ignore errors and try the common path
59
+ setupEnv();
43
60
  return yield Promise.resolve(`${`../bin/${process.platform}/${process.arch}/llama-node.node`}`).then(s => __importStar(require(s)));
44
61
  });
45
62
  exports.loadModule = loadModule;
package/lib/binding.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import * as path from 'path'
2
+
1
3
  export type LlamaModelOptions = {
2
4
  model: string
3
5
  embedding?: boolean
@@ -48,11 +50,26 @@ export interface Module {
48
50
  LlamaContext: LlamaContext
49
51
  }
50
52
 
53
+ const setupEnv = (variant?: string) => {
54
+ const postfix = variant ? `-${variant}` : ''
55
+ const binPath = path.resolve(__dirname, `../bin/${process.platform}${postfix}/${process.arch}/`)
56
+ const systemPathEnv = process.env.PATH ?? process.env.Path ?? ''
57
+ if (!systemPathEnv.includes(binPath)) {
58
+ if (process.platform === 'win32') {
59
+ process.env.Path = `${binPath};${systemPathEnv}`
60
+ } else {
61
+ process.env.PATH = `${binPath}:${systemPathEnv}`
62
+ }
63
+ }
64
+ }
65
+
51
66
  export const loadModule = async (variant?: string): Promise<Module> => {
52
67
  try {
53
68
  if (variant) {
69
+ setupEnv(variant)
54
70
  return await import(`../bin/${process.platform}-${variant}/${process.arch}/llama-node.node`) as Module
55
71
  }
56
72
  } catch {} // ignore errors and try the common path
73
+ setupEnv()
57
74
  return await import(`../bin/${process.platform}/${process.arch}/llama-node.node`) as Module
58
75
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fugood/llama.node",
3
3
  "access": "public",
4
- "version": "0.0.1-alpha.3",
4
+ "version": "0.0.1-alpha.4",
5
5
  "description": "Llama.cpp for Node.js",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {