Skip to content

Commit 9d1d245

Browse files
committed
server : do not inject reasoning if content is present
1 parent f72c6eb commit 9d1d245

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
@@ -672,10 +672,27 @@ struct reasoning_cache {
672672
}
673673

674674
for (auto &msg : messages) {
675+
std::string role = json_value(msg, "role", std::string());
676+
if (role != "assistant") {
677+
continue;
678+
}
679+
675680
if (!msg.contains("tool_calls") || msg.contains("reasoning_content")) {
676681
continue;
677682
}
678683

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

0 commit comments

Comments
 (0)