Spaces:
Running
Running
Lin Xiaodong
linxiaodong
commited on
addon.node : support max_context api for addon.node (#3025)
Browse files* feat: support max content
* feat: show api in test file
---------
Co-authored-by: linxiaodong <[email protected]>
examples/addon.node/__test__/whisper.spec.js
CHANGED
|
@@ -19,6 +19,12 @@ const whisperParamsMock = {
|
|
| 19 |
no_timestamps: false,
|
| 20 |
audio_ctx: 0,
|
| 21 |
max_len: 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
};
|
| 23 |
|
| 24 |
describe("Run whisper.node", () => {
|
|
|
|
| 19 |
no_timestamps: false,
|
| 20 |
audio_ctx: 0,
|
| 21 |
max_len: 0,
|
| 22 |
+
prompt: "",
|
| 23 |
+
print_progress: false,
|
| 24 |
+
progress_callback: (progress) => {
|
| 25 |
+
console.log(`Progress: ${progress}`);
|
| 26 |
+
},
|
| 27 |
+
max_context: -1
|
| 28 |
};
|
| 29 |
|
| 30 |
describe("Run whisper.node", () => {
|
examples/addon.node/addon.cpp
CHANGED
|
@@ -368,6 +368,12 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
|
|
| 368 |
bool comma_in_time = whisper_params.Get("comma_in_time").As<Napi::Boolean>();
|
| 369 |
int32_t max_len = whisper_params.Get("max_len").As<Napi::Number>();
|
| 370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
// support prompt
|
| 372 |
std::string prompt = "";
|
| 373 |
if (whisper_params.Has("prompt") && whisper_params.Get("prompt").IsString()) {
|
|
@@ -407,6 +413,7 @@ Napi::Value whisper(const Napi::CallbackInfo& info) {
|
|
| 407 |
params.pcmf32 = pcmf32_vec;
|
| 408 |
params.comma_in_time = comma_in_time;
|
| 409 |
params.max_len = max_len;
|
|
|
|
| 410 |
params.print_progress = print_progress;
|
| 411 |
params.prompt = prompt;
|
| 412 |
|
|
|
|
| 368 |
bool comma_in_time = whisper_params.Get("comma_in_time").As<Napi::Boolean>();
|
| 369 |
int32_t max_len = whisper_params.Get("max_len").As<Napi::Number>();
|
| 370 |
|
| 371 |
+
// Add support for max_context
|
| 372 |
+
int32_t max_context = -1;
|
| 373 |
+
if (whisper_params.Has("max_context") && whisper_params.Get("max_context").IsNumber()) {
|
| 374 |
+
max_context = whisper_params.Get("max_context").As<Napi::Number>();
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
// support prompt
|
| 378 |
std::string prompt = "";
|
| 379 |
if (whisper_params.Has("prompt") && whisper_params.Get("prompt").IsString()) {
|
|
|
|
| 413 |
params.pcmf32 = pcmf32_vec;
|
| 414 |
params.comma_in_time = comma_in_time;
|
| 415 |
params.max_len = max_len;
|
| 416 |
+
params.max_context = max_context;
|
| 417 |
params.print_progress = print_progress;
|
| 418 |
params.prompt = prompt;
|
| 419 |
|