@@ -1441,6 +1441,64 @@ static void test_template_output_parsers() {
14411441 }
14421442}
14431443
1444+ static void test_gpt_oss_parser () {
1445+ printf (" [%s]\n " , __func__);
1446+
1447+ // Standard commentary header with explicit ' json'
1448+ {
1449+ const std::string input =
1450+ " <|start|>assistant<|channel|>commentary to=functions.shell json<|message|>" \
1451+ " {\\\" command\\\" :[\\\" bash\\\" ,\\\" -lc\\\" ,\\\" echo hi\\\" ]}" \
1452+ " <|start|>assistant<|channel|>final<|message|>Done" ;
1453+ common_chat_msg expected = simple_assist_msg (" Done" , " " , " shell" ,
1454+ " {\" command\" :[\" bash\" ,\" -lc\" ,\" echo hi\" ]}" );
1455+ assert_msg_equals (
1456+ expected,
1457+ common_chat_parse (
1458+ input,
1459+ /* is_partial= */ false ,
1460+ {COMMON_CHAT_FORMAT_GPT_OSS}));
1461+ }
1462+
1463+ // Commentary header where 'json' is glued to function name (e.g., 'shelljson')
1464+ {
1465+ const std::string input =
1466+ " <|start|>assistant<|channel|>commentary to=functions.shelljson<|message|>" \
1467+ " {\\\" command\\\" :[\\\" bash\\\" ,\\\" -lc\\\" ,\\\" echo hi\\\" ]}" \
1468+ " <|start|>assistant<|channel|>final<|message|>Done" ;
1469+ common_chat_msg expected = simple_assist_msg (" Done" , " " , " shell" ,
1470+ " {\" command\" :[\" bash\" ,\" -lc\" ,\" echo hi\" ]}" );
1471+ assert_msg_equals (
1472+ expected,
1473+ common_chat_parse (
1474+ input,
1475+ /* is_partial= */ false ,
1476+ {COMMON_CHAT_FORMAT_GPT_OSS}));
1477+ }
1478+
1479+ // Multiple commentary tool calls then final
1480+ {
1481+ const std::string input =
1482+ " <|start|>assistant<|channel|>commentary to=functions.shell json<|message|>" \
1483+ " {\\\" command\\\" :[\\\" bash\\\" ,\\\" -lc\\\" ,\\\" echo hi\\\" ]}" \
1484+ " <|start|>assistant<|channel|>commentary to=functions.update_plan json<|message|>" \
1485+ " {\\\" plan\\\" :[{\\\" step\\\" :\\\" x\\\" ,\\\" status\\\" :\\\" in_progress\\\" }]}" \
1486+ " <|start|>assistant<|channel|>final<|message|>ok" ;
1487+ common_chat_msg expected;
1488+ expected.role = " assistant" ;
1489+ expected.content = " ok" ;
1490+ expected.tool_calls .push_back ({" shell" , " {\" command\" :[\" bash\" ,\" -lc\" ,\" echo hi\" ]}" , " " });
1491+ expected.tool_calls .push_back ({" update_plan" , " {\" plan\" :[{\" step\" :\" x\" ,\" status\" :\" in_progress\" }]}" , " " });
1492+
1493+ assert_msg_equals (
1494+ expected,
1495+ common_chat_parse (
1496+ input,
1497+ /* is_partial= */ false ,
1498+ {COMMON_CHAT_FORMAT_GPT_OSS}));
1499+ }
1500+ }
1501+
14441502static void test_msg_diffs_compute () {
14451503 printf (" [%s]\n " , __func__);
14461504 {
@@ -1564,6 +1622,7 @@ int main(int argc, char ** argv) {
15641622 test_msgs_oaicompat_json_conversion ();
15651623 test_tools_oaicompat_json_conversion ();
15661624 test_template_output_parsers ();
1625+ test_gpt_oss_parser ();
15671626 std::cout << " \n [chat] All tests passed!" << ' \n ' ;
15681627 }
15691628 return 0 ;
0 commit comments