@fugood/llama.node 1.0.5 → 1.0.6

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/lib/binding.ts CHANGED
@@ -231,7 +231,7 @@ export interface LlamaContext {
231
231
  * @param path Path to the vocoder model
232
232
  * @returns Promise resolving to true if loading was successful
233
233
  */
234
- initVocoder(options: { path: string }): Promise<boolean>
234
+ initVocoder(options: { path: string, n_batch?: number }): Promise<boolean>
235
235
 
236
236
  /**
237
237
  * Unload the vocoder model
package/lib/index.ts CHANGED
@@ -286,7 +286,7 @@ class LlamaContextWrapper {
286
286
  return this.ctx.getMultimodalSupport()
287
287
  }
288
288
 
289
- initVocoder(options: { path: string }): Promise<boolean> {
289
+ initVocoder(options: { path: string, n_batch?: number }): Promise<boolean> {
290
290
  return this.ctx.initVocoder(options)
291
291
  }
292
292
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fugood/llama.node",
3
3
  "access": "public",
4
- "version": "1.0.5",
4
+ "version": "1.0.6",
5
5
  "description": "An another Node binding of llama.cpp",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -70,19 +70,19 @@
70
70
  "CMakeLists.txt"
71
71
  ],
72
72
  "optionalDependencies": {
73
- "@fugood/node-llama-linux-x64": "1.0.5",
74
- "@fugood/node-llama-linux-x64-vulkan": "1.0.5",
75
- "@fugood/node-llama-linux-x64-cuda": "1.0.5",
76
- "@fugood/node-llama-linux-arm64": "1.0.5",
77
- "@fugood/node-llama-linux-arm64-vulkan": "1.0.5",
78
- "@fugood/node-llama-linux-arm64-cuda": "1.0.5",
79
- "@fugood/node-llama-win32-x64": "1.0.5",
80
- "@fugood/node-llama-win32-x64-vulkan": "1.0.5",
81
- "@fugood/node-llama-win32-x64-cuda": "1.0.5",
82
- "@fugood/node-llama-win32-arm64": "1.0.5",
83
- "@fugood/node-llama-win32-arm64-vulkan": "1.0.5",
84
- "@fugood/node-llama-darwin-x64": "1.0.5",
85
- "@fugood/node-llama-darwin-arm64": "1.0.5"
73
+ "@fugood/node-llama-linux-x64": "1.0.6",
74
+ "@fugood/node-llama-linux-x64-vulkan": "1.0.6",
75
+ "@fugood/node-llama-linux-x64-cuda": "1.0.6",
76
+ "@fugood/node-llama-linux-arm64": "1.0.6",
77
+ "@fugood/node-llama-linux-arm64-vulkan": "1.0.6",
78
+ "@fugood/node-llama-linux-arm64-cuda": "1.0.6",
79
+ "@fugood/node-llama-win32-x64": "1.0.6",
80
+ "@fugood/node-llama-win32-x64-vulkan": "1.0.6",
81
+ "@fugood/node-llama-win32-x64-cuda": "1.0.6",
82
+ "@fugood/node-llama-win32-arm64": "1.0.6",
83
+ "@fugood/node-llama-win32-arm64-vulkan": "1.0.6",
84
+ "@fugood/node-llama-darwin-x64": "1.0.6",
85
+ "@fugood/node-llama-darwin-arm64": "1.0.6"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@babel/preset-env": "^7.24.4",
@@ -1,5 +1,6 @@
1
1
  #include "LlamaCompletionWorker.h"
2
2
  #include "LlamaContext.h"
3
+ #include <limits>
3
4
 
4
5
  size_t findStoppingStrings(const std::string &text,
5
6
  const size_t last_token_size,
@@ -124,11 +125,11 @@ void LlamaCompletionWorker::Execute() {
124
125
  _sess->set_tokens(std::move(prompt_tokens));
125
126
  }
126
127
 
127
- const int max_len = _params.n_predict < 0 ? 0 : _params.n_predict;
128
+ const int max_len = _params.n_predict < 0 ? std::numeric_limits<int>::max() : _params.n_predict;
128
129
  _sess->tokens_ptr()->reserve(_sess->tokens_ptr()->size() + max_len);
129
130
 
130
131
  auto embd = _sess->tokens_ptr();
131
- for (int i = 0; i < max_len || _stop; i++) {
132
+ for (int i = 0; (i < max_len || _stop) && !_params.vocab_only; i++) {
132
133
  // check if we need to remove some tokens
133
134
  if (embd->size() >= _params.n_ctx) {
134
135
  if (!_params.ctx_shift) {
@@ -1291,14 +1291,16 @@ tts_type LlamaContext::getTTSType(Napi::Env env, nlohmann::json speaker) {
1291
1291
  return OUTETTS_V0_2;
1292
1292
  }
1293
1293
 
1294
- // initVocoder(path: string): boolean
1294
+ // initVocoder(params?: object): boolean
1295
1295
  Napi::Value LlamaContext::InitVocoder(const Napi::CallbackInfo &info) {
1296
1296
  Napi::Env env = info.Env();
1297
1297
  if (info.Length() < 1 || !info[0].IsObject()) {
1298
- Napi::TypeError::New(env, "Object is expected for vocoder path")
1298
+ Napi::TypeError::New(env, "Object is expected for vocoder options")
1299
1299
  .ThrowAsJavaScriptException();
1300
1300
  }
1301
- auto vocoder_path = info[0].As<Napi::Object>().Get("path").ToString().Utf8Value();
1301
+ auto options = info[0].As<Napi::Object>();
1302
+ auto vocoder_path = options.Get("path").ToString().Utf8Value();
1303
+ auto n_batch = get_option<int32_t>(options, "n_batch", _sess->params().n_batch);
1302
1304
  if (vocoder_path.empty()) {
1303
1305
  Napi::TypeError::New(env, "vocoder path is required")
1304
1306
  .ThrowAsJavaScriptException();
@@ -1314,6 +1316,7 @@ Napi::Value LlamaContext::InitVocoder(const Napi::CallbackInfo &info) {
1314
1316
  _vocoder.params.model.path = vocoder_path;
1315
1317
  _vocoder.params.embedding = true;
1316
1318
  _vocoder.params.ctx_shift = false;
1319
+ _vocoder.params.n_batch = n_batch;
1317
1320
  _vocoder.params.n_ubatch = _vocoder.params.n_batch;
1318
1321
  common_init_result result = common_init_from_params(_vocoder.params);
1319
1322
  if (result.model == nullptr || result.context == nullptr) {