diff --git a/common/chat.cpp b/common/chat.cpp index 938872e82ee1d..b9357db989bb1 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -201,6 +201,7 @@ std::vector common_chat_msgs_parse_oaicompat(const json & messa msg.role = message.at("role"); auto has_content = message.contains("content"); + auto has_reasoning_content = message.contains("reasoning_content"); auto has_tool_calls = message.contains("tool_calls"); if (has_content) { const auto & content = message.at("content"); @@ -249,8 +250,8 @@ std::vector common_chat_msgs_parse_oaicompat(const json & messa msg.tool_calls.push_back(tc); } } - if (!has_content && !has_tool_calls) { - throw std::runtime_error("Expected 'content' or 'tool_calls' (ref: https://github.com/ggml-org/llama.cpp/issues/8367 & https://github.com/ggml-org/llama.cpp/issues/12279)"); + if (!has_content && !has_tool_calls && !has_reasoning_content) { + throw std::runtime_error("Expected 'content', 'reasoning_content' or 'tool_calls' (ref: https://github.com/ggml-org/llama.cpp/issues/8367 & https://github.com/ggml-org/llama.cpp/issues/12279)"); } if (message.contains("reasoning_content")) { msg.reasoning_content = message.at("reasoning_content"); diff --git a/tools/server/tests/unit/test_chat_completion.py b/tools/server/tests/unit/test_chat_completion.py index 392e0efecdbbd..8c7b6ef9f835a 100644 --- a/tools/server/tests/unit/test_chat_completion.py +++ b/tools/server/tests/unit/test_chat_completion.py @@ -476,3 +476,16 @@ def make_cmpl_request(): assert last_progress["total"] > 0 assert last_progress["processed"] == last_progress["total"] assert total_batch_count == batch_count + + +def test_standalone_reasoning_content_is_accepted(): + global server + server.start() + res = server.make_request("POST", "/chat/completions", data={ + "max_tokens": 8, + "messages": [ + {"role": "user", "content": "How much is 102 + 7?"}, + {"role": "assistant", "reasoning_content": "Calculate."}, + ] + }) + assert res.status_code == 200 diff --git a/tools/server/utils.hpp b/tools/server/utils.hpp index 2bce2f4a47af9..a56095d331b7e 100644 --- a/tools/server/utils.hpp +++ b/tools/server/utils.hpp @@ -595,8 +595,8 @@ static json oaicompat_chat_params_parse( throw std::runtime_error("All non-assistant messages must contain 'content'"); } if (role == "assistant") { - if (!msg.contains("content") && !msg.contains("tool_calls")) { - throw std::runtime_error("Assistant message must contain either 'content' or 'tool_calls'!"); + if (!msg.contains("content") && !msg.contains("tool_calls") && !msg.contains("reasoning_content")) { + throw std::runtime_error("Assistant message must contain either 'content' or 'tool_calls' or 'reasoning_content'!"); } if (!msg.contains("content")) { continue; // avoid errors with no content