MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / parseMetadata

Function parseMetadata

plugins/wasi_nn/wasinn_whisper.cpp:518–808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516}
517
518Expect<ErrNo> parseMetadata(Config &ConfigRef,
519 const std::string &Metadata) noexcept {
520 simdjson::dom::parser Parser;
521 simdjson::dom::element Doc;
522 auto ParseError = Parser.parse(Metadata).get(Doc);
523 if (ParseError) {
524 spdlog::error("[WASI-NN] Whisper backend: Parse metadata error."sv);
525 return ErrNo::InvalidEncoding;
526 }
527
528 auto PrintParsedOption = [&](std::string_view Name, const auto &Val) {
529 if (ConfigRef.EnableDebugLog) {
530 spdlog::info(
531 "[WASI-NN][Debug] Whisper backend: Parsed metadata -- {}:{}"sv, Name,
532 Val);
533 }
534 };
535
536 // Get metadata from the json.
537 // Currently supported metadata:
538 // Plugin parameters (used by this plugin):
539 // enable-log: bool
540 // enable-debug-log: bool
541 // threads: uint32_t
542 // processors: uint32_t
543 // offset-t: uint32_t
544 // duration: uint32_t
545 // max-context: uint32_t
546 // max-len: uint32_t
547 // split-on-word: bool
548 // translate: bool
549 // language: string
550 // detect-language: bool
551 // temperature: float
552 // prompt: string
553
554 // The plugin parameters.
555 if (Doc.at_key("enable-log").error() == simdjson::SUCCESS) {
556 auto Err = Doc["enable-log"].get<bool>().get(ConfigRef.EnableLog);
557 if (Err) {
558 spdlog::error(
559 "[WASI-NN] Whisper backend: Unable to retrieve the enable-log "
560 "option."sv);
561 return ErrNo::InvalidArgument;
562 }
563 }
564 if (Doc.at_key("enable-debug-log").error() == simdjson::SUCCESS) {
565 auto Err =
566 Doc["enable-debug-log"].get<bool>().get(ConfigRef.EnableDebugLog);
567 if (Err) {
568 spdlog::error(
569 "[WASI-NN] Whisper backend: Unable to retrieve the enable-debug-log "
570 "option."sv);
571 return ErrNo::InvalidArgument;
572 }
573 }
574 if (Doc.at_key("threads").error() == simdjson::SUCCESS) {
575 auto Err = Doc["threads"].get<uint64_t>().get(ConfigRef.ThreadsNum);

Callers 2

loadFunction · 0.70
setInputFunction · 0.70

Calls 3

errorFunction · 0.50
getMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected