| 1321 | } |
| 1322 | |
| 1323 | static void expect_tool_parameters(const std::string & name, const json & parameters, const std::vector<std::string> & expected_properties) { |
| 1324 | if (!parameters.is_object() || !parameters.contains("type") || parameters.at("type") != "object" || !parameters.contains("properties") || !parameters.contains("required")) { |
| 1325 | throw std::runtime_error("Parameters of tool " + name + " must be an object w/ required properties"); |
| 1326 | } |
| 1327 | const auto & parameters_properties = parameters.at("properties"); |
| 1328 | const auto & parameters_required = parameters.at("required"); |
| 1329 | for (const auto & prop : expected_properties) { |
| 1330 | if (!parameters_properties.contains(prop)) { |
| 1331 | throw std::runtime_error("Parameters of tool " + name + " is missing property: " + prop); // NOLINT |
| 1332 | } |
| 1333 | if (std::find(parameters_required.begin(), parameters_required.end(), json(prop)) == parameters_required.end()) { |
| 1334 | throw std::runtime_error("Parameters of tool " + name + " must have property marked as required: " + prop); // NOLINT |
| 1335 | } |
| 1336 | } |
| 1337 | if (parameters_properties.size() != expected_properties.size()) { |
| 1338 | throw std::runtime_error("Parameters of tool " + name + " must only have these properties:" + string_join(expected_properties, ", ")); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | static common_chat_params common_chat_params_init_llama_3_x(const common_chat_template & tmpl, const struct templates_params & inputs, bool allow_python_tag_builtin_tools) { |
| 1343 | auto builtin_tools = json::array(); |
no test coverage detected