Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix case where only one stream chunk is returned
  • Loading branch information
ngxson committed Nov 13, 2025
commit 3be8a3ac0c6c65e5b458d05d82c9889af603ffeb
22 changes: 12 additions & 10 deletions tools/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5205,6 +5205,17 @@ struct server_routes {
server_response_reader & rd = res_this->rd;
std::string & output = res_this->data;

// check if there is more data
if (!rd.has_next()) {
if (oaicompat != OAICOMPAT_TYPE_NONE) {
output = "data: [DONE]\n\n";
} else {
output = "";
}
SRV_DBG("%s", "all results received, terminating stream\n");
return false; // no more data, terminate
}

// receive subsequent results
auto result = rd.next(should_stop);
if (result == nullptr) {
Expand All @@ -5215,7 +5226,7 @@ struct server_routes {
// send the results
json res_json = result->to_json();
if (result->is_error()) {
output = format_sse(res_json);
output = format_sse(json {{ "error", res_json }});
SRV_DBG("%s", "error received during streaming, terminating stream\n");
return false; // terminate on error
} else {
Expand All @@ -5226,15 +5237,6 @@ struct server_routes {
output = format_sse(res_json);
}

// check if there is more data
if (!rd.has_next()) {
if (oaicompat != OAICOMPAT_TYPE_NONE) {
output += "data: [DONE]\n\n";
}
SRV_DBG("%s", "all results received, terminating stream\n");
return false; // no more data, terminate
}

// has next data, continue
return true;
};
Expand Down