| 1383 | return data; |
| 1384 | } |
| 1385 | static void common_chat_parse_functionary_v3_2(common_chat_msg_parser & builder) { |
| 1386 | static const common_regex function_regex_start_only(R"((\w+\n\{|python\n|all\n))"); |
| 1387 | static const common_regex function_regex(R"(>>>(\w+\n\{|python\n|all\n))"); |
| 1388 | static const common_regex close_regex(R"(\s*)"); |
| 1389 | |
| 1390 | parse_json_tool_calls( |
| 1391 | builder, |
| 1392 | std::nullopt, |
| 1393 | function_regex_start_only, |
| 1394 | function_regex, |
| 1395 | close_regex, |
| 1396 | std::nullopt, |
| 1397 | /* allow_raw_python= */ true, |
| 1398 | /* get_function_name= */ [&](const auto & res) -> std::string { |
| 1399 | auto at_start = res.groups[0].begin == 0; |
| 1400 | auto name = builder.str(res.groups[1]); |
| 1401 | if (!name.empty() && name.back() == '{') { |
| 1402 | // Unconsume the opening brace '{' to ensure the JSON parsing goes well. |
| 1403 | builder.move_back(1); |
| 1404 | } |
| 1405 | auto idx = name.find_last_not_of("\n{"); |
| 1406 | name = name.substr(0, idx + 1); |
| 1407 | if (at_start && name == "all") { |
| 1408 | return ""; |
| 1409 | } |
| 1410 | return name; |
| 1411 | }); |
| 1412 | } |
| 1413 | |
| 1414 | static common_chat_params common_chat_params_init_functionary_v3_1_llama_3_1(const common_chat_template & tmpl, const struct templates_params & inputs) { |
| 1415 | // https://github.com/MeetKai/functionary/blob/main/tests/prompt_test_v3-llama3.1.txt |
no test coverage detected