Skip to content

Commit af63886

Browse files
author
ochafik
committed
return reasoning_content before content
1 parent c0f972b commit af63886

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

examples/server/server.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,19 @@ struct server_task_result_cmpl_final : server_task_result {
725725
msg.content = content;
726726
}
727727

728-
json tool_calls;
728+
json message {
729+
{"role", "assistant"},
730+
};
731+
if (!msg.reasoning_content.empty()) {
732+
message["reasoning_content"] = msg.reasoning_content;
733+
}
734+
if (msg.content == "" && !msg.tool_calls.empty()) {
735+
message["content"] = json();
736+
} else {
737+
message["content"] = msg.content;
738+
}
729739
if (!msg.tool_calls.empty()) {
730-
tool_calls = json::array();
740+
auto tool_calls = json::array();
731741
for (const auto & tc : msg.tool_calls) {
732742
tool_calls.push_back({
733743
{"type", "function"},
@@ -738,15 +748,7 @@ struct server_task_result_cmpl_final : server_task_result {
738748
{"id", tc.id},
739749
});
740750
}
741-
}
742-
743-
json message {
744-
{"content", msg.content == "" && !tool_calls.empty() ? json() : json(msg.content)},
745-
{"tool_calls", tool_calls},
746-
{"role", "assistant"},
747-
};
748-
if (!msg.reasoning_content.empty()) {
749-
message["reasoning_content"] = msg.reasoning_content;
751+
message["tool_calls"] = tool_calls;
750752
}
751753

752754
json choice {

0 commit comments

Comments
 (0)