]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
addon.node : support max_context api for addon.node (#3025)
authorLin Xiaodong <redacted>
Fri, 11 Apr 2025 04:36:38 +0000 (12:36 +0800)
committerGitHub <redacted>
Fri, 11 Apr 2025 04:36:38 +0000 (06:36 +0200)
* feat: support max content

* feat: show api in test file

---------

Co-authored-by: linxiaodong <redacted>
examples/addon.node/__test__/whisper.spec.js
examples/addon.node/addon.cpp

index 066f382b8eb40b3d0681634bb920c83c8e22eea4..142c4e31d3f9af7512a3e0c731f20a05d4053cdb 100644 (file)
@@ -19,6 +19,12 @@ const whisperParamsMock = {
   no_timestamps: false,
   audio_ctx: 0,
   max_len: 0,
+  prompt: "",
+  print_progress: false,
+  progress_callback: (progress) => {
+    console.log(`Progress: ${progress}`);
+  },
+  max_context: -1
 };
 
 describe("Run whisper.node", () => {
index d4773ce08e7c617f6325770dc1b5b88d7175210d..3c1d52cbcd967159a97441b8da83883e986ae6b0 100644 (file)
@@ -368,6 +368,12 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
   bool comma_in_time = whisper_params.Get("comma_in_time").As<Napi::Boolean>();
   int32_t max_len = whisper_params.Get("max_len").As<Napi::Number>();
   
+  // Add support for max_context
+  int32_t max_context = -1;
+  if (whisper_params.Has("max_context") && whisper_params.Get("max_context").IsNumber()) {
+    max_context = whisper_params.Get("max_context").As<Napi::Number>();
+  }
+  
   // support prompt
   std::string prompt = "";
   if (whisper_params.Has("prompt") && whisper_params.Get("prompt").IsString()) {
@@ -407,6 +413,7 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
   params.pcmf32 = pcmf32_vec;
   params.comma_in_time = comma_in_time;
   params.max_len = max_len;
+  params.max_context = max_context;
   params.print_progress = print_progress;
   params.prompt = prompt;