palito 0.7.0 → 0.7.2

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 (3) hide show
  1. package/index.js +5 -1
  2. package/koffi.js +18 -0
  3. package/package.json +24 -3
package/index.js CHANGED
@@ -8,7 +8,10 @@
8
8
 
9
9
  const fs = require('node:fs');
10
10
  const path = require('node:path');
11
- const koffi = require('koffi');
11
+ const { loadKoffi } = require('./koffi.js');
12
+
13
+ // Loaded on first use, so installing on a platform without a prebuilt never fails.
14
+ let koffi = null;
12
15
 
13
16
  const DEVICES = { default: 0, cpu: 1, cuda: 2 };
14
17
  const FINISH_REASONS = ['stop', 'length', 'context_full', 'cancelled'];
@@ -43,6 +46,7 @@ function load() {
43
46
  const file = libraryPath();
44
47
  let lib;
45
48
  try {
49
+ koffi = koffi || loadKoffi();
46
50
  lib = koffi.load(file);
47
51
  } catch (error) {
48
52
  throw new PalitoError(`cannot load ${file}: ${error.message}. Install Palito or set PALITO_LIBRARY`);
package/koffi.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+ // Loads koffi's prebuilt package for this platform. Palito depends on these
3
+ // directly because the `koffi` package's install script fails pnpm's default install.
4
+
5
+ function koffiPackage(platform, arch) {
6
+ return `@koromix/koffi-${platform}-${arch}`;
7
+ }
8
+
9
+ function loadKoffi(platform = process.platform, arch = process.arch, load = require) {
10
+ const name = koffiPackage(platform, arch);
11
+ try {
12
+ return load(name);
13
+ } catch (error) {
14
+ throw new Error(`no prebuilt koffi for ${platform}-${arch} (${name}): ${error.message}`);
15
+ }
16
+ }
17
+
18
+ module.exports = { koffiPackage, loadKoffi };
package/package.json CHANGED
@@ -1,14 +1,35 @@
1
1
  {
2
2
  "name": "palito",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Node.js binding for Palito, fast local LLM inference for GGUF models",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/natanloterio/palito#readme",
7
7
  "repository": { "type": "git", "url": "git+https://github.com/natanloterio/palito.git", "directory": "bindings/node" },
8
8
  "main": "index.js",
9
9
  "types": "index.d.ts",
10
- "files": ["index.js", "index.d.ts", "README.md"],
10
+ "files": ["index.js", "index.d.ts", "koffi.js", "README.md"],
11
11
  "engines": { "node": ">=18" },
12
12
  "scripts": { "test": "node --test test/*.test.js" },
13
- "dependencies": { "koffi": "^3.3.8" }
13
+ "optionalDependencies": {
14
+ "@koromix/koffi-android-arm64": "^3.3.8",
15
+ "@koromix/koffi-android-x64": "^3.3.8",
16
+ "@koromix/koffi-darwin-arm64": "^3.3.8",
17
+ "@koromix/koffi-darwin-x64": "^3.3.8",
18
+ "@koromix/koffi-freebsd-arm64": "^3.3.8",
19
+ "@koromix/koffi-freebsd-ia32": "^3.3.8",
20
+ "@koromix/koffi-freebsd-x64": "^3.3.8",
21
+ "@koromix/koffi-linux-arm": "^3.3.8",
22
+ "@koromix/koffi-linux-arm64": "^3.3.8",
23
+ "@koromix/koffi-linux-ia32": "^3.3.8",
24
+ "@koromix/koffi-linux-loong64": "^3.3.8",
25
+ "@koromix/koffi-linux-ppc64": "^3.3.8",
26
+ "@koromix/koffi-linux-riscv64": "^3.3.8",
27
+ "@koromix/koffi-linux-x64": "^3.3.8",
28
+ "@koromix/koffi-openbsd-arm64": "^3.3.8",
29
+ "@koromix/koffi-openbsd-ia32": "^3.3.8",
30
+ "@koromix/koffi-openbsd-x64": "^3.3.8",
31
+ "@koromix/koffi-win32-arm64": "^3.3.8",
32
+ "@koromix/koffi-win32-ia32": "^3.3.8",
33
+ "@koromix/koffi-win32-x64": "^3.3.8"
34
+ }
14
35
  }