@fugood/llama.node 1.3.0-rc.0 → 1.3.0-rc.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/CMakeLists.txt CHANGED
@@ -124,6 +124,8 @@ include_directories(
124
124
  ${CMAKE_JS_INC}
125
125
  "src/llama.cpp"
126
126
  "src/llama.cpp/src"
127
+ "src/llama.cpp/ggml/include"
128
+ "src/llama.cpp/ggml/src"
127
129
  "src/tools/mtmd"
128
130
  )
129
131
 
package/lib/binding.js CHANGED
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
35
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
27
  return new (P || (P = Promise))(function (resolve, reject) {
package/lib/binding.ts CHANGED
@@ -236,6 +236,36 @@ export type LlamaCompletionToken = {
236
236
  completion_probabilities?: CompletionProbability[]
237
237
  }
238
238
 
239
+ /**
240
+ * Result from a parallel completion request (queueCompletion callback).
241
+ * Extends the basic completion result with per-slot timing information.
242
+ */
243
+ export type LlamaParallelCompletionResult = {
244
+ requestId: number
245
+ text: string
246
+ reasoning_content?: string
247
+ content?: string
248
+ tool_calls?: ToolCall[]
249
+ chat_format: number
250
+ stopped_eos: boolean
251
+ stopped_limit: boolean
252
+ stopped_word: boolean
253
+ context_full: boolean
254
+ tokens_evaluated: number
255
+ tokens_predicted: number
256
+ timings: {
257
+ cache_n: number
258
+ prompt_n: number
259
+ prompt_ms: number
260
+ prompt_per_token_ms: number
261
+ prompt_per_second: number
262
+ predicted_n: number
263
+ predicted_ms: number
264
+ predicted_per_token_ms: number
265
+ predicted_per_second: number
266
+ }
267
+ }
268
+
239
269
  export type TokenizeResult = {
240
270
  tokens: Int32Array
241
271
  has_media: boolean
@@ -257,6 +287,14 @@ export type RerankResult = {
257
287
  index: number
258
288
  }
259
289
 
290
+ export type BackendDeviceInfo = {
291
+ backend: string
292
+ type: string
293
+ deviceName: string
294
+ maxMemorySize: number
295
+ metadata?: Record<string, any>
296
+ }
297
+
260
298
  export type ModelInfo = {
261
299
  desc: string
262
300
  nEmbd: number
@@ -457,12 +495,12 @@ export interface LlamaContext {
457
495
  /**
458
496
  * Queue a completion request for parallel processing
459
497
  * @param options Completion options with parallel-specific state management
460
- * @param callback Optional token callback
498
+ * @param callback Optional callback that receives tokens during generation and final result
461
499
  * @returns Object with requestId
462
500
  */
463
501
  queueCompletion(
464
502
  options: LlamaParallelCompletionOptions,
465
- callback?: (error: any, result: any) => void,
503
+ callback?: (error: any, result: LlamaParallelCompletionResult) => void,
466
504
  ): { requestId: number }
467
505
 
468
506
  /**
@@ -505,6 +543,11 @@ export interface LlamaContext {
505
543
  enable: boolean,
506
544
  callback: (level: string, text: string) => void,
507
545
  ): void
546
+ /**
547
+ * Get information about available backend devices
548
+ * @returns Array of backend device information
549
+ */
550
+ getBackendDevicesInfo(): BackendDeviceInfo[]
508
551
  }
509
552
 
510
553
  export interface Module {
package/lib/index.js CHANGED
@@ -23,7 +23,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  });
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.BuildInfo = exports.loadLlamaModelInfo = exports.initLlama = exports.loadModel = exports.toggleNativeLog = exports.MTMD_DEFAULT_MEDIA_MARKER = exports.LlamaParallelAPI = void 0;
26
+ exports.BuildInfo = exports.getBackendDevicesInfo = exports.loadLlamaModelInfo = exports.initLlama = exports.loadModel = exports.toggleNativeLog = exports.MTMD_DEFAULT_MEDIA_MARKER = exports.LlamaParallelAPI = void 0;
27
27
  exports.addNativeLogListener = addNativeLogListener;
28
28
  const binding_1 = require("./binding");
29
29
  const version_1 = require("./version");
@@ -269,6 +269,14 @@ const loadLlamaModelInfo = (path) => __awaiter(void 0, void 0, void 0, function*
269
269
  return mods[variant].LlamaContext.loadModelInfo(path, modelInfoSkip);
270
270
  });
271
271
  exports.loadLlamaModelInfo = loadLlamaModelInfo;
272
+ const getBackendDevicesInfo = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (variant = 'default') {
273
+ var _a;
274
+ (_a = mods[variant]) !== null && _a !== void 0 ? _a : (mods[variant] = yield (0, binding_1.loadModule)(variant));
275
+ refreshNativeLogSetup();
276
+ const jsonString = mods[variant].LlamaContext.getBackendDevicesInfo();
277
+ return JSON.parse(jsonString);
278
+ });
279
+ exports.getBackendDevicesInfo = getBackendDevicesInfo;
272
280
  exports.BuildInfo = {
273
281
  number: version_1.BUILD_NUMBER,
274
282
  commit: version_1.BUILD_COMMIT,
package/lib/index.ts CHANGED
@@ -385,6 +385,15 @@ export const loadLlamaModelInfo = async (
385
385
  return mods[variant].LlamaContext.loadModelInfo(path, modelInfoSkip)
386
386
  }
387
387
 
388
+ export const getBackendDevicesInfo = async (
389
+ variant: LibVariant = 'default'
390
+ ): Promise<import('./binding').BackendDeviceInfo[]> => {
391
+ mods[variant] ??= await loadModule(variant)
392
+ refreshNativeLogSetup()
393
+ const jsonString = mods[variant].LlamaContext.getBackendDevicesInfo()
394
+ return JSON.parse(jsonString as any)
395
+ }
396
+
388
397
  export const BuildInfo = {
389
398
  number: BUILD_NUMBER,
390
399
  commit: BUILD_COMMIT,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fugood/llama.node",
3
3
  "access": "public",
4
- "version": "1.3.0-rc.0",
4
+ "version": "1.3.0-rc.1",
5
5
  "description": "An another Node binding of llama.cpp",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -72,19 +72,19 @@
72
72
  "CMakeLists.txt"
73
73
  ],
74
74
  "optionalDependencies": {
75
- "@fugood/node-llama-linux-x64": "1.3.0-rc.0",
76
- "@fugood/node-llama-linux-x64-vulkan": "1.3.0-rc.0",
77
- "@fugood/node-llama-linux-x64-cuda": "1.3.0-rc.0",
78
- "@fugood/node-llama-linux-arm64": "1.3.0-rc.0",
79
- "@fugood/node-llama-linux-arm64-vulkan": "1.3.0-rc.0",
80
- "@fugood/node-llama-linux-arm64-cuda": "1.3.0-rc.0",
81
- "@fugood/node-llama-win32-x64": "1.3.0-rc.0",
82
- "@fugood/node-llama-win32-x64-vulkan": "1.3.0-rc.0",
83
- "@fugood/node-llama-win32-x64-cuda": "1.3.0-rc.0",
84
- "@fugood/node-llama-win32-arm64": "1.3.0-rc.0",
85
- "@fugood/node-llama-win32-arm64-vulkan": "1.3.0-rc.0",
86
- "@fugood/node-llama-darwin-x64": "1.3.0-rc.0",
87
- "@fugood/node-llama-darwin-arm64": "1.3.0-rc.0"
75
+ "@fugood/node-llama-linux-x64": "1.3.0-rc.1",
76
+ "@fugood/node-llama-linux-x64-vulkan": "1.3.0-rc.1",
77
+ "@fugood/node-llama-linux-x64-cuda": "1.3.0-rc.1",
78
+ "@fugood/node-llama-linux-arm64": "1.3.0-rc.1",
79
+ "@fugood/node-llama-linux-arm64-vulkan": "1.3.0-rc.1",
80
+ "@fugood/node-llama-linux-arm64-cuda": "1.3.0-rc.1",
81
+ "@fugood/node-llama-win32-x64": "1.3.0-rc.1",
82
+ "@fugood/node-llama-win32-x64-vulkan": "1.3.0-rc.1",
83
+ "@fugood/node-llama-win32-x64-cuda": "1.3.0-rc.1",
84
+ "@fugood/node-llama-win32-arm64": "1.3.0-rc.1",
85
+ "@fugood/node-llama-win32-arm64-vulkan": "1.3.0-rc.1",
86
+ "@fugood/node-llama-darwin-x64": "1.3.0-rc.1",
87
+ "@fugood/node-llama-darwin-arm64": "1.3.0-rc.1"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@babel/preset-env": "^7.24.4",
@@ -89,6 +89,13 @@ Napi::Value LlamaContext::ModelInfo(const Napi::CallbackInfo &info) {
89
89
  return metadata;
90
90
  }
91
91
 
92
+ // getBackendDevicesInfo(): string
93
+ Napi::Value LlamaContext::GetBackendDevicesInfo(const Napi::CallbackInfo &info) {
94
+ Napi::Env env = info.Env();
95
+ std::string devices_json = rnllama::get_backend_devices_info();
96
+ return Napi::String::New(env, devices_json);
97
+ }
98
+
92
99
  void LlamaContext::Init(Napi::Env env, Napi::Object &exports) {
93
100
  Napi::Function func = DefineClass(
94
101
  env, "LlamaContext",
@@ -148,6 +155,9 @@ void LlamaContext::Init(Napi::Env env, Napi::Object &exports) {
148
155
  StaticMethod<&LlamaContext::ToggleNativeLog>(
149
156
  "toggleNativeLog",
150
157
  static_cast<napi_property_attributes>(napi_enumerable)),
158
+ StaticMethod<&LlamaContext::GetBackendDevicesInfo>(
159
+ "getBackendDevicesInfo",
160
+ static_cast<napi_property_attributes>(napi_enumerable)),
151
161
  InstanceMethod<&LlamaContext::GetMultimodalSupport>(
152
162
  "getMultimodalSupport",
153
163
  static_cast<napi_property_attributes>(napi_enumerable)),
@@ -25,6 +25,7 @@ public:
25
25
  ~LlamaContext();
26
26
  static void ToggleNativeLog(const Napi::CallbackInfo &info);
27
27
  static Napi::Value ModelInfo(const Napi::CallbackInfo &info);
28
+ static Napi::Value GetBackendDevicesInfo(const Napi::CallbackInfo &info);
28
29
  static void Init(Napi::Env env, Napi::Object &exports);
29
30
 
30
31
  private: