Skip to content

Commit d95c39f

Browse files
committed
server : do not inject reasoning if content is present
1 parent f0eb26b commit d95c39f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tools/server/server.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,27 @@ struct reasoning_cache {
668668
}
669669

670670
for (auto &msg : messages) {
671+
std::string role = json_value(msg, "role", std::string());
672+
if (role != "assistant") {
673+
continue;
674+
}
675+
671676
if (!msg.contains("tool_calls") || msg.contains("reasoning_content")) {
672677
continue;
673678
}
674679

680+
// do not inject if the message contains a non-empty content
681+
if (msg.contains("content")) {
682+
if (msg.at("content").is_string()) {
683+
std::string content = json_value(msg, "content", std::string());
684+
if (!content.empty()) {
685+
continue;
686+
}
687+
} else if (!msg.at("content").empty()) {
688+
continue;
689+
}
690+
}
691+
675692
// inject cached reasoning to tool call messages to support models that require it (gpt-oss)
676693
const json & tool_calls = msg.at("tool_calls");
677694
if (tool_calls.is_array() && !tool_calls.empty()) {

0 commit comments

Comments
 (0)