| 142 | return WASINN::ErrNo::Success; |
| 143 | } |
| 144 | WASINN::ErrNo parseRunConfig(RunConfig &RunConfig, |
| 145 | const std::string &String) noexcept { |
| 146 | simdjson::dom::parser Parser; |
| 147 | simdjson::dom::element Doc; |
| 148 | if (auto Error = Parser.parse(String).get(Doc)) { |
| 149 | spdlog::error("[WASI-NN] Piper backend: Parse run config error: {}"sv, |
| 150 | simdjson::error_message(Error)); |
| 151 | return WASINN::ErrNo::InvalidEncoding; |
| 152 | } |
| 153 | simdjson::dom::object Object; |
| 154 | if (auto Error = Doc.get(Object)) { |
| 155 | spdlog::error( |
| 156 | "[WASI-NN] Piper backend: The run config is not an object: {}"sv, |
| 157 | simdjson::error_message(Error)); |
| 158 | return WASINN::ErrNo::InvalidArgument; |
| 159 | } |
| 160 | |
| 161 | auto ModelPath = std::optional<std::string_view>{}; |
| 162 | if (auto Err = getOptionalOption(Object, "model", ModelPath); |
| 163 | Err != WASINN::ErrNo::Success) { |
| 164 | return Err; |
| 165 | } |
| 166 | // Verify model file exists |
| 167 | if (ModelPath) { |
| 168 | auto Path = std::filesystem::u8path(ModelPath.value()); |
| 169 | if (!std::filesystem::exists(Path)) { |
| 170 | spdlog::error("[WASI-NN] Piper backend: Model file doesn't exist"sv); |
| 171 | return WASINN::ErrNo::InvalidArgument; |
| 172 | } |
| 173 | RunConfig.ModelPath = Path; |
| 174 | } else { |
| 175 | spdlog::error( |
| 176 | "[WASI-NN] Piper backend: The model option is required but not provided"sv); |
| 177 | return WASINN::ErrNo::InvalidArgument; |
| 178 | } |
| 179 | |
| 180 | auto ModelConfigPath = std::optional<std::string_view>{}; |
| 181 | if (auto Err = getOptionalOption(Object, "config", ModelConfigPath); |
| 182 | Err != WASINN::ErrNo::Success) { |
| 183 | return Err; |
| 184 | } |
| 185 | if (ModelConfigPath) { |
| 186 | RunConfig.ModelConfigPath = |
| 187 | std::filesystem::u8path(ModelConfigPath.value()); |
| 188 | } else { |
| 189 | RunConfig.ModelConfigPath = RunConfig.ModelPath; |
| 190 | RunConfig.ModelConfigPath += ".json"; |
| 191 | } |
| 192 | // Verify model config exists |
| 193 | if (!std::filesystem::exists(RunConfig.ModelConfigPath)) { |
| 194 | spdlog::error("[WASI-NN] Piper backend: Model config doesn't exist"sv); |
| 195 | return WASINN::ErrNo::InvalidArgument; |
| 196 | } |
| 197 | |
| 198 | if (auto Err = parseSynthesisConfig(RunConfig.DefaultSynthesisConfig, Object); |
| 199 | Err != WASINN::ErrNo::Success) { |
| 200 | return Err; |
| 201 | } |
no test coverage detected