MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / common_chat_tools_parse_oaicompat

Function common_chat_tools_parse_oaicompat

common/chat.cpp:419–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

417}
418
419std::vector<common_chat_tool> common_chat_tools_parse_oaicompat(const json & tools) {
420 std::vector<common_chat_tool> result;
421
422 try {
423 if (!tools.is_null()) {
424 if (!tools.is_array()) {
425 throw std::invalid_argument("Expected 'tools' to be an array, got " + tools.dump());
426 }
427 for (const auto & tool : tools) {
428 if (!tool.contains("type")) {
429 throw std::invalid_argument("Missing tool type: " + tool.dump());
430 }
431 const auto & type = tool.at("type");
432 if (!type.is_string() || type != "function") {
433 throw std::invalid_argument("Unsupported tool type: " + tool.dump());
434 }
435 if (!tool.contains("function")) {
436 throw std::invalid_argument("Missing tool function: " + tool.dump());
437 }
438
439 const auto & function = tool.at("function");
440 result.push_back({
441 /* .name = */ function.at("name"),
442 /* .description = */ function.value("description", ""),
443 /* .parameters = */ function.value("parameters", json::object()).dump(),
444 });
445 }
446 }
447 } catch (const std::exception & e) {
448 throw std::runtime_error("Failed to parse tools: " + std::string(e.what()) + "; tools = " + tools.dump(2));
449 }
450
451 return result;
452}
453
454bool common_chat_verify_template(const std::string & tmpl, bool use_jinja) {
455 if (use_jinja) {

Callers 3

run_singleFunction · 0.85

Calls 5

stringClass · 0.85
dumpMethod · 0.80
containsMethod · 0.80
push_backMethod · 0.45
whatMethod · 0.45

Tested by 2

run_singleFunction · 0.68