Skip to content

Commit

Permalink
Merge pull request #21 from silvioprog/no-debug-info-in-prod
Browse files Browse the repository at this point in the history
feat: allow to disable debug info in production
  • Loading branch information
JacobLinCool authored Jan 28, 2024
2 parents 1ead6ee + ebb91e7 commit 7b6c3f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-weeks-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"smart-whisper": minor
---

Allow to disable debug info in production
16 changes: 16 additions & 0 deletions src/binding/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ class LoadModelWorker : public Napi::AsyncWorker {
whisper_context *context;
};

bool IsProduction(const Napi::Object global_env) {
Napi::Object process = global_env.Get("process").As<Napi::Object>();
Napi::Object env = process.Get("env").As<Napi::Object>();
Napi::Value nodeEnv = env.Get("NODE_ENV");
if (nodeEnv.IsString()) {
Napi::String nodeEnvStr = nodeEnv.As<Napi::String>();
std::string envStr = nodeEnvStr.Utf8Value();
return envStr == "production";
}
return false;
}

Napi::Value LoadModel(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();

Expand All @@ -42,6 +54,10 @@ Napi::Value LoadModel(const Napi::CallbackInfo &info) {

Napi::Function callback = info[2].As<Napi::Function>();

if (IsProduction(env.Global())) {
whisper_log_set([](ggml_log_level level, const char *text, void *user_data) {}, nullptr);
}

LoadModelWorker *worker = new LoadModelWorker(callback, model_path, params);
worker->Queue();

Expand Down

0 comments on commit 7b6c3f1

Please sign in to comment.