@@ -273,6 +273,17 @@ const common_chat_msg message_user {
273273 /* .tool_calls = */ {},
274274 /* .reasoning_content = */ " " ,
275275};
276+
277+ const common_chat_msg message_user_parts {
278+ " user" ,
279+ /* .content = */ " " ,
280+ /* .content_parts = */ {
281+ { " text" , " Hey" },
282+ { " text" , " there" },
283+ },
284+ /* .tool_calls = */ {},
285+ /* .reasoning_content = */ " " ,
286+ };
276287const common_chat_msg message_assist {
277288 " assistant" ,
278289 " Hello, world!\n What's up?" ,
@@ -375,8 +386,10 @@ const common_chat_msg message_assist_call_code_interpreter {
375386 /* .tool_call_id = */ " " ,
376387};
377388
378- static void test_oaicompat_json_conversion () {
389+ static void test_msgs_oaicompat_json_conversion () {
379390 std::vector<common_chat_msg> msgs{
391+ message_user,
392+ message_user_parts,
380393 message_assist_call,
381394 message_assist_call_thoughts,
382395 message_assist_call_thoughts_unparsed,
@@ -392,6 +405,26 @@ static void test_oaicompat_json_conversion() {
392405 auto msg2 = msgs2[0 ];
393406 assert_msg_equals (msg, msg2);
394407 }
408+ assert_equals (
409+ std::string (
410+ " [\n "
411+ " {\n "
412+ " \" role\" : \" user\" ,\n "
413+ " \" content\" : [\n "
414+ " {\n "
415+ " \" type\" : \" text\" ,\n "
416+ " \" text\" : \" Hey\"\n "
417+ " },\n "
418+ " {\n "
419+ " \" type\" : \" text\" ,\n "
420+ " \" text\" : \" there\"\n "
421+ " }\n "
422+ " ]\n "
423+ " }\n "
424+ " ]"
425+ ),
426+ common_chat_msgs_to_json_oaicompat<json>({message_user_parts}).dump (2 ));
427+
395428 assert_equals (
396429 std::string (
397430 " [\n "
@@ -411,7 +444,9 @@ static void test_oaicompat_json_conversion() {
411444 " ]"
412445 ),
413446 common_chat_msgs_to_json_oaicompat<json>({message_assist_call_python}).dump (2 ));
447+ }
414448
449+ static void test_tools_oaicompat_json_conversion () {
415450 std::vector<common_chat_tool> tools{
416451 special_function_tool,
417452 python_tool,
@@ -772,7 +807,8 @@ int main(int argc, char ** argv) {
772807 } else
773808#endif
774809 {
775- test_oaicompat_json_conversion ();
810+ test_msgs_oaicompat_json_conversion ();
811+ test_tools_oaicompat_json_conversion ();
776812 test_template_output_parsers ();
777813 std::cout << " \n [chat] All tests passed!" << std::endl;
778814 }
0 commit comments