File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -643,6 +643,18 @@ static json oaicompat_completion_params_parse(
643
643
throw std::runtime_error (" Expected 'messages' to be an array" );
644
644
}
645
645
for (auto & msg : messages) {
646
+ std::string role = json_value (msg, " role" , std::string ());
647
+ if (role != " assistant" && !msg.contains (" content" )) {
648
+ throw std::runtime_error (" All non-assistant messages must contain 'content'" );
649
+ }
650
+ if (role == " assistant" ) {
651
+ if (!msg.contains (" content" ) && !msg.contains (" tool_calls" )) {
652
+ throw std::runtime_error (" Assistant message must contain either 'content' or 'tool_calls'!" );
653
+ }
654
+ if (!msg.contains (" content" )) {
655
+ continue ; // avoid errors with no content
656
+ }
657
+ }
646
658
json & content = msg.at (" content" );
647
659
if (content.is_string () || content.is_null ()) {
648
660
continue ;
You can’t perform that action at this time.
0 commit comments