| 31 | |
| 32 | template <typename T> |
| 33 | static T json_value(const json & body, const std::string & key, const T & default_value) { |
| 34 | // Fallback null to default value |
| 35 | if (body.contains(key) && !body.at(key).is_null()) { |
| 36 | try { |
| 37 | return body.at(key); |
| 38 | } catch (NLOHMANN_JSON_NAMESPACE::detail::type_error const & err) { |
| 39 | LOG_WRN("Wrong type supplied for parameter '%s'. Expected '%s', using default value: %s\n", key.c_str(), json(default_value).type_name(), err.what()); |
| 40 | return default_value; |
| 41 | } |
| 42 | } else { |
| 43 | return default_value; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | // https://community.openai.com/t/openai-chat-list-of-error-codes-and-types/357791/11 |
| 48 | enum error_type { |
no test coverage detected