MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / expect_tool_parameters

Function expect_tool_parameters

smallthinker/common/chat.cpp:1034–1051  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1032}
1033
1034static 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
1053static 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();

Callers 1

Calls 5

string_joinFunction · 0.85
findFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected