| 833 | return data; |
| 834 | } |
| 835 | static void common_chat_parse_generic(common_chat_msg_parser & builder) { |
| 836 | if (!builder.syntax().parse_tool_calls) { |
| 837 | builder.add_content(builder.consume_rest()); |
| 838 | return; |
| 839 | } |
| 840 | static const std::vector<std::vector<std::string>> content_paths = { |
| 841 | {"response"}, |
| 842 | }; |
| 843 | static const std::vector<std::vector<std::string>> args_paths = { |
| 844 | {"tool_call", "arguments"}, |
| 845 | {"tool_calls", "arguments"}, |
| 846 | }; |
| 847 | auto data = builder.consume_json_with_dumped_args(args_paths, content_paths); |
| 848 | if (data.value.contains("tool_calls")) { |
| 849 | if (!builder.add_tool_calls(data.value.at("tool_calls")) || data.is_partial) { |
| 850 | throw common_chat_msg_partial_exception("incomplete tool calls"); |
| 851 | } |
| 852 | } else if (data.value.contains("tool_call")) { |
| 853 | if (!builder.add_tool_call(data.value.at("tool_call")) || data.is_partial) { |
| 854 | throw common_chat_msg_partial_exception("incomplete tool call"); |
| 855 | } |
| 856 | } else if (data.value.contains("response")) { |
| 857 | const auto & response = data.value.at("response"); |
| 858 | builder.add_content(response.is_string() ? response.template get<std::string>() : response.dump(2)); |
| 859 | if (data.is_partial) { |
| 860 | throw common_chat_msg_partial_exception("incomplete response"); |
| 861 | } |
| 862 | } else { |
| 863 | throw common_chat_msg_partial_exception("Expected 'tool_call', 'tool_calls' or 'response' in JSON"); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | static common_chat_params common_chat_params_init_mistral_nemo(const common_chat_template & tmpl, const struct templates_params & inputs) { |
| 868 | common_chat_params data; |
no test coverage detected