@@ -313,7 +313,6 @@ json common_chat_msgs_to_json_oaicompat(const std::vector<common_chat_msg> & msg
313313 }
314314 if (!msg.reasoning_content .empty ()) {
315315 jmsg[" reasoning_content" ] = msg.reasoning_content ;
316- jmsg[" thinking" ] = msg.reasoning_content ; // gpt-oss
317316 }
318317 if (!msg.tool_name .empty ()) {
319318 jmsg[" name" ] = msg.tool_name ;
@@ -1810,7 +1809,23 @@ static void common_chat_parse_deepseek_v3_1(common_chat_msg_parser & builder) {
18101809
18111810static common_chat_params common_chat_params_init_gpt_oss (const common_chat_template & tmpl, const struct templates_params & inputs) {
18121811 common_chat_params data;
1813- auto prompt = apply (tmpl, inputs);
1812+
1813+ // Copy reasoning to the "thinking" field as expected by the gpt-oss template
1814+ auto adjusted_messages = json::array ();
1815+ for (const auto & msg : inputs.messages ) {
1816+ auto has_reasoning_content = msg.contains (" reasoning_content" ) && msg.at (" reasoning_content" ).is_string ();
1817+ auto has_tool_calls = msg.contains (" tool_calls" ) && msg.at (" tool_calls" ).is_array ();
1818+
1819+ if (has_reasoning_content && has_tool_calls) {
1820+ auto adjusted_message = msg;
1821+ adjusted_message[" thinking" ] = msg.at (" reasoning_content" );
1822+ adjusted_messages.push_back (adjusted_message);
1823+ } else {
1824+ adjusted_messages.push_back (msg);
1825+ }
1826+ }
1827+
1828+ auto prompt = apply (tmpl, inputs, /* messages_override= */ adjusted_messages);
18141829
18151830 // Check if we need to replace the return token with end token during
18161831 // inference and without generation prompt. For more details see:
0 commit comments