| 1032 | } |
| 1033 | |
| 1034 | static void expect_tool_parameters(const std::string & name, const json & parameters, const std::vector<std::string> & expected_properties) { |
| 1035 | if (!parameters.is_object() || !parameters.contains("type") || parameters.at("type") != "object" || !parameters.contains("properties") || !parameters.contains("required")) { |
| 1036 | throw std::runtime_error("Parameters of tool " + name + " must be an object w/ required properties"); |
| 1037 | } |
| 1038 | const auto & parameters_properties = parameters.at("properties"); |
| 1039 | const auto & parameters_required = parameters.at("required"); |
| 1040 | for (const auto & prop : expected_properties) { |
| 1041 | if (!parameters_properties.contains(prop)) { |
| 1042 | throw std::runtime_error("Parameters of tool " + name + " is missing property: " + prop); // NOLINT |
| 1043 | } |
| 1044 | if (std::find(parameters_required.begin(), parameters_required.end(), json(prop)) == parameters_required.end()) { |
| 1045 | throw std::runtime_error("Parameters of tool " + name + " must have property marked as required: " + prop); // NOLINT |
| 1046 | } |
| 1047 | } |
| 1048 | if (parameters_properties.size() != expected_properties.size()) { |
| 1049 | throw std::runtime_error("Parameters of tool " + name + " must only have these properties:" + string_join(expected_properties, ", ")); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | 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) { |
| 1054 | auto builtin_tools = json::array(); |
no test coverage detected