Skip to content

Commit f16589b

Browse files
shun095aa254201
authored andcommitted
tests: add test cases for Granite models chat parser
1 parent 836e859 commit f16589b

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

tests/test-chat.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,12 @@ static void test_template_output_parsers() {
14001400
"Hello, world!\nWhat's up?",
14011401
/* is_partial= */ false,
14021402
{COMMON_CHAT_FORMAT_GRANITE}));
1403+
assert_msg_equals(
1404+
message_assist,
1405+
common_chat_parse(
1406+
"Hello, world!\nWhat's up?",
1407+
/* is_partial= */ true,
1408+
{COMMON_CHAT_FORMAT_GRANITE}));
14031409

14041410
// Test parsing content with thinking
14051411
assert_msg_equals(message_assist_thoughts,
@@ -1410,13 +1416,98 @@ static void test_template_output_parsers() {
14101416
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
14111417
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
14121418
}));
1419+
assert_msg_equals(message_assist_thoughts_unparsed_deepseek,
1420+
common_chat_parse(
1421+
"<think>I'm\nthinking</think>Hello, world!\nWhat's up?",
1422+
/* is_partial= */ false,
1423+
{COMMON_CHAT_FORMAT_GRANITE}));
1424+
assert_msg_equals(message_assist_thoughts,
1425+
common_chat_parse(
1426+
"<think>I'm\nthinking</think><response>Hello, world!\nWhat's up?",
1427+
/* is_partial= */ true,
1428+
{
1429+
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
1430+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1431+
}));
1432+
assert_msg_equals(message_assist_thoughts,
1433+
common_chat_parse(
1434+
"<think>I'm\nthinking</think><response>Hello, world!\nWhat's up?</response>",
1435+
/* is_partial= */ false,
1436+
{
1437+
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
1438+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1439+
}));
1440+
assert_msg_equals(simple_assist_msg("<think>I'm\nthinking</think><response>Hello, world!\nWhat's up?</response>"),
1441+
common_chat_parse(
1442+
"<think>I'm\nthinking</think><response>Hello, world!\nWhat's up?</response>",
1443+
/* is_partial= */ false,
1444+
{COMMON_CHAT_FORMAT_GRANITE}));
1445+
assert_msg_equals(message_assist_empty,
1446+
common_chat_parse(
1447+
"<think",
1448+
/* is_partial= */ true,
1449+
{
1450+
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
1451+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1452+
}));
1453+
assert_msg_equals(message_assist_empty,
1454+
common_chat_parse(
1455+
"<think",
1456+
/* is_partial= */ true,
1457+
{COMMON_CHAT_FORMAT_GRANITE}));
1458+
assert_msg_equals(message_assist_thoughts_no_content,
1459+
common_chat_parse(
1460+
"<think>I'm\nthinking",
1461+
/* is_partial= */ true,
1462+
{
1463+
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
1464+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1465+
}));
1466+
assert_msg_equals(
1467+
message_assist_empty,
1468+
common_chat_parse(
1469+
"<think>I'm\nthinking</think><response",
1470+
/* is_partial= */ true,
1471+
{COMMON_CHAT_FORMAT_GRANITE}));
14131472

14141473
// Test parsing tool calls
14151474
assert_msg_equals(message_assist_call,
14161475
common_chat_parse(
14171476
"<|tool_call|>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}}]",
14181477
/* is_partial= */ false,
14191478
{COMMON_CHAT_FORMAT_GRANITE}));
1479+
assert_msg_equals(
1480+
message_assist_call_empty_args,
1481+
common_chat_parse(
1482+
"<|tool_call|>[{\"name\": \"special_function\"",
1483+
/* is_partial= */ true,
1484+
{COMMON_CHAT_FORMAT_GRANITE}));
1485+
assert_msg_equals(
1486+
message_assist_call_cutoff_args,
1487+
common_chat_parse(
1488+
"<|tool_call|>[{\"name\": \"special_function\", \"arguments\": {\"arg",
1489+
/* is_partial= */ true,
1490+
{COMMON_CHAT_FORMAT_GRANITE}));
1491+
assert_msg_equals(
1492+
message_assist_call_cutoff_args,
1493+
common_chat_parse(
1494+
"<|tool_call|>[{\"name\": \"special_function\", \"arguments\": {\"arg",
1495+
/* is_partial= */ true,
1496+
{
1497+
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
1498+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1499+
}));
1500+
1501+
// Test parsing tool calls with thinking
1502+
assert_msg_equals(
1503+
message_assist_call_thoughts,
1504+
common_chat_parse(
1505+
"<think>I'm\nthinking</think><|tool_call|>[{\"name\": \"special_function\", \"arguments\": {\"arg1\": 1}, {",
1506+
/* is_partial= */ true,
1507+
{
1508+
/* .format = */ COMMON_CHAT_FORMAT_GRANITE,
1509+
/* .reasoning_format = */ COMMON_REASONING_FORMAT_DEEPSEEK,
1510+
}));
14201511

14211512
// Test template generation for regular content
14221513
test_templates(tmpls.get(), end_tokens, message_assist, tools,

0 commit comments

Comments
 (0)