Skip to content

Added whisper_get_system_info_json #3027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/whisper.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ extern "C" {

// Print system information
WHISPER_API const char * whisper_print_system_info(void);
WHISPER_API const char * whisper_get_system_info_json(void);

////////////////////////////////////////////////////////////////////////////

Expand Down
42 changes: 42 additions & 0 deletions src/whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4346,6 +4346,48 @@ const char * whisper_print_system_info(void) {
return s.c_str();
}

// whisper_get_system_info_json
// Returns system info as json, useful for ports
// NOTE : While testing features->value always returned a numeric so it is currently unquoted
// If strings are likely then something slightly more type-aware will be required
const char * whisper_get_system_info_json(void) {
static std::string s;

whisper_load_backends();

s = "{";
s += "\"WHISPER\":{";
s += "\"COREML\":" + std::to_string(whisper_has_coreml()) + ",";
s += "\"OPENVINO\":" + std::to_string(whisper_has_openvino()) + "}";

for (size_t i = 0; i < ggml_backend_reg_count(); i++) {
auto * reg = ggml_backend_reg_get(i);
auto * get_features_fn = (ggml_backend_get_features_t) ggml_backend_reg_get_proc_address(reg, "ggml_backend_get_features");
if (get_features_fn) {
ggml_backend_feature * features = get_features_fn(reg);
s += ",\"";
s += ggml_backend_reg_name(reg);
s += "\":{";
auto first = true;
for (; features->name; features++) {
if(first) {
first = false;
} else {
s += ",";
}
s += "\"";
s += features->name;
s += "\":";
s += features->value;
}
s += "}";
}
}
s += "}";

return s.c_str();
}

//////////////////////////////////
// Grammar - ported from llama.cpp
//////////////////////////////////
Expand Down
Loading