| 696 | } |
| 697 | |
| 698 | static void parse_prefixed_json_tool_call_array(common_chat_msg_parser & builder, const common_regex & prefix, size_t rstrip_prefix = 0) { |
| 699 | static const std::vector<std::vector<std::string>> args_paths = {{"arguments"}}; |
| 700 | if (auto res = builder.try_find_regex(prefix)) { |
| 701 | builder.move_back(rstrip_prefix); |
| 702 | auto tool_calls = builder.consume_json_with_dumped_args(args_paths); |
| 703 | if (!builder.add_tool_calls(tool_calls.value) || tool_calls.is_partial) { |
| 704 | throw common_chat_msg_partial_exception("incomplete tool call array"); |
| 705 | } |
| 706 | } else { |
| 707 | builder.add_content(builder.consume_rest()); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | static void foreach_function(const json & tools, const std::function<void(const json &)> & fn) { |
| 712 | for (const auto & tool : tools) { |
no test coverage detected