|
|
@@ -420,6 +420,7 @@ const common_chat_msg message_assist_call_empty_args = simple_assist
|
|
|
const common_chat_msg message_assist_call_cutoff_args = simple_assist_msg("", "", "special_function", "{\"arg");
|
|
|
const common_chat_msg message_assist_call_thoughts = simple_assist_msg("", "I'm\nthinking", "special_function", "{\"arg1\":1}");
|
|
|
const common_chat_msg message_assist_call_thoughts_unparsed = simple_assist_msg("<think>I'm\nthinking</think>\n\n", "", "special_function", "{\"arg1\": 1}");
|
|
|
+const common_chat_msg message_assist_call_thoughts_content = simple_assist_msg("Hello, world!\nWhat's up?", "I'm\nthinking", "special_function", "{\"arg1\": 1}");
|
|
|
const common_chat_msg message_assist_call_id = simple_assist_msg("", "", "special_function", "{\"arg1\":1}", /* .id = */ "123456789");
|
|
|
const common_chat_msg message_assist_call_idx = simple_assist_msg("", "", "special_function", "{\"arg1\":1}", /* .id = */ "0");
|
|
|
const common_chat_msg message_assist_thoughts_call_idx = simple_assist_msg("", "I'm\nthinking", "special_function", "{\"arg1\": 1}", /* id = */ "0");
|
|
|
@@ -436,6 +437,7 @@ static void test_msgs_oaicompat_json_conversion() {
|
|
|
message_assist_call,
|
|
|
message_assist_call_thoughts,
|
|
|
message_assist_call_thoughts_unparsed,
|
|
|
+ message_assist_call_thoughts_content,
|
|
|
message_assist_call_id,
|
|
|
message_assist_call_idx,
|
|
|
message_assist_call_python,
|
|
|
@@ -1755,6 +1757,77 @@ static void test_template_output_parsers() {
|
|
|
/* is_partial= */ false,
|
|
|
{COMMON_CHAT_FORMAT_SEED_OSS}));
|
|
|
}
|
|
|
+
|
|
|
+ {
|
|
|
+ auto tmpls = read_templates("models/templates/NVIDIA-Nemotron-Nano-v2.jinja");
|
|
|
+ std::vector<std::string> end_tokens{ "<SPECIAL_12>" };
|
|
|
+
|
|
|
+ assert_equals(COMMON_CHAT_FORMAT_NEMOTRON_V2, common_chat_templates_apply(tmpls.get(), inputs_no_tools).format);
|
|
|
+ assert_equals(COMMON_CHAT_FORMAT_NEMOTRON_V2, common_chat_templates_apply(tmpls.get(), inputs_tools).format);
|
|
|
+
|
|
|
+ // Test parsing regular content
|
|
|
+ assert_msg_equals(message_assist,
|
|
|
+ common_chat_parse(
|
|
|
+ "Hello, world!\nWhat's up?",
|
|
|
+ /* is_partial= */ false,
|
|
|
+ {COMMON_CHAT_FORMAT_NEMOTRON_V2}));
|
|
|
+
|
|
|
+ // Test parsing content with thinking
|
|
|
+ assert_msg_equals(message_assist_thoughts,
|
|
|
+ common_chat_parse(
|
|
|
+ "<think>I'm\nthinking</think>Hello, world!\nWhat's up?",
|
|
|
+ /* is_partial= */ false,
|
|
|
+ {
|
|
|
+ /* .format = */ COMMON_CHAT_FORMAT_NEMOTRON_V2,
|
|
|
+ /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
|
|
|
+ }));
|
|
|
+
|
|
|
+ // Test parsing tool calls
|
|
|
+ assert_msg_equals(message_assist_call,
|
|
|
+ common_chat_parse(
|
|
|
+ "<TOOLCALL>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}]</TOOLCALL>",
|
|
|
+ /* is_partial= */ false,
|
|
|
+ {COMMON_CHAT_FORMAT_NEMOTRON_V2}));
|
|
|
+
|
|
|
+ // Test parsing tool calls with thinking
|
|
|
+ assert_msg_equals(message_assist_call_thoughts,
|
|
|
+ common_chat_parse(
|
|
|
+ "<think>I'm\nthinking</think><TOOLCALL>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}]</TOOLCALL>",
|
|
|
+ /* is_partial= */ false,
|
|
|
+ {
|
|
|
+ /* .format = */ COMMON_CHAT_FORMAT_NEMOTRON_V2,
|
|
|
+ /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK
|
|
|
+ }));
|
|
|
+
|
|
|
+ // Test tool calls with extra content
|
|
|
+ assert_msg_equals(message_assist_call_content,
|
|
|
+ common_chat_parse(
|
|
|
+ "<TOOLCALL>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}]</TOOLCALL>Hello, world!\nWhat's up?",
|
|
|
+ /* is_partial= */ false,
|
|
|
+ {COMMON_CHAT_FORMAT_NEMOTRON_V2}
|
|
|
+ ));
|
|
|
+
|
|
|
+ // Test tool calls with extra content AND thinking
|
|
|
+ assert_msg_equals(message_assist_call_thoughts_content,
|
|
|
+ common_chat_parse(
|
|
|
+ "<think>I'm\nthinking</think><TOOLCALL>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}]</TOOLCALL>Hello, world!\nWhat's up?",
|
|
|
+ /* is_partial= */ false,
|
|
|
+ {
|
|
|
+ /* .format = */ COMMON_CHAT_FORMAT_NEMOTRON_V2,
|
|
|
+ /* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK
|
|
|
+ }));
|
|
|
+
|
|
|
+ // Test template generation for regular content
|
|
|
+ test_templates(tmpls.get(), end_tokens, message_assist, tools,
|
|
|
+ "Hello, world!\nWhat's up?\n",
|
|
|
+ /* expect_grammar_triggered= */ false);
|
|
|
+
|
|
|
+ // Test template generation for tool calls
|
|
|
+ test_templates(tmpls.get(), end_tokens, message_assist_call, tools,
|
|
|
+ "<TOOLCALL>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}]</TOOLCALL>",
|
|
|
+ /* expect_grammar_triggered= */ true
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static void test_msg_diffs_compute() {
|