Skip to content

Commit de4343a

Browse files
committed
chat: Allow reasoning_content to be passed back
This makes it possible for reasoning_content to be passed back to llama-server, which is useful for LLMs like GPT-OSS or Minimax-M2 that were trained for this.
1 parent 76af40a commit de4343a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

common/chat.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ std::vector<common_chat_msg> common_chat_msgs_parse_oaicompat(const json & messa
201201
msg.role = message.at("role");
202202

203203
auto has_content = message.contains("content");
204+
auto has_reasoning_content = message.contains("reasoning_content");
204205
auto has_tool_calls = message.contains("tool_calls");
205206
if (has_content) {
206207
const auto & content = message.at("content");
@@ -249,8 +250,8 @@ std::vector<common_chat_msg> common_chat_msgs_parse_oaicompat(const json & messa
249250
msg.tool_calls.push_back(tc);
250251
}
251252
}
252-
if (!has_content && !has_tool_calls) {
253-
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)");
253+
if (!has_content && !has_tool_calls && !has_reasoning_content) {
254+
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)");
254255
}
255256
if (message.contains("reasoning_content")) {
256257
msg.reasoning_content = message.at("reasoning_content");

tools/server/utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ static json oaicompat_chat_params_parse(
595595
throw std::runtime_error("All non-assistant messages must contain 'content'");
596596
}
597597
if (role == "assistant") {
598-
if (!msg.contains("content") && !msg.contains("tool_calls")) {
599-
throw std::runtime_error("Assistant message must contain either 'content' or 'tool_calls'!");
598+
if (!msg.contains("content") && !msg.contains("tool_calls") && !msg.contains("reasoning_content")) {
599+
throw std::runtime_error("Assistant message must contain either 'content' or 'tool_calls' or 'reasoning_content'!");
600600
}
601601
if (!msg.contains("content")) {
602602
continue; // avoid errors with no content

0 commit comments

Comments
 (0)