MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / expect_tool_parameters

Function expect_tool_parameters

subprojects/llama.cpp/common/chat.cpp:1323–1340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1321}
1322
1323static 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
1342static 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();

Callers 1

Calls 6

string_joinFunction · 0.85
containsMethod · 0.65
atMethod · 0.65
sizeMethod · 0.65
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected