Skip to content

Commit ba2af58

Browse files
committed
add safe-guard
1 parent abe598b commit ba2af58

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

tools/server/server-task.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ std::vector<unsigned char> completion_token_output::str_to_bytes(const std::stri
565565
// server_task_result_cmpl_final
566566
//
567567
json server_task_result_cmpl_final::to_json() {
568+
GGML_ASSERT(is_updated && "update() must be called before to_json()");
568569
switch (res_type) {
569570
case TASK_RESPONSE_TYPE_NONE:
570571
return to_json_non_oaicompat();
@@ -975,6 +976,7 @@ json server_task_result_cmpl_final::to_json_anthropic_stream() {
975976
// server_task_result_cmpl_partial
976977
//
977978
json server_task_result_cmpl_partial::to_json() {
979+
GGML_ASSERT(is_updated && "update() must be called before to_json()");
978980
switch (res_type) {
979981
case TASK_RESPONSE_TYPE_NONE:
980982
return to_json_non_oaicompat();

tools/server/server-task.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ struct server_task_result_cmpl_final : server_task_result {
258258
common_chat_msg oaicompat_msg; // to be populated by update()
259259

260260
std::vector<common_chat_msg_diff> oaicompat_msg_diffs; // to be populated by update()
261+
bool is_updated = false;
261262

262263
virtual int get_index() override {
263264
return index;
@@ -270,6 +271,7 @@ struct server_task_result_cmpl_final : server_task_result {
270271
virtual json to_json() override;
271272

272273
virtual void update(task_result_state & state) override {
274+
is_updated = true;
273275
oaicompat_msg = state.update_chat_msg(content, false, oaicompat_msg_diffs);
274276
}
275277

@@ -307,6 +309,7 @@ struct server_task_result_cmpl_partial : server_task_result {
307309
std::string oaicompat_model;
308310
std::string oaicompat_cmpl_id;
309311
std::vector<common_chat_msg_diff> oaicompat_msg_diffs; // to be populated by update()
312+
bool is_updated = false;
310313

311314
virtual int get_index() override {
312315
return index;
@@ -319,6 +322,7 @@ struct server_task_result_cmpl_partial : server_task_result {
319322
virtual json to_json() override;
320323

321324
virtual void update(task_result_state & state) override {
325+
is_updated = true;
322326
state.update_chat_msg(content, true, oaicompat_msg_diffs);
323327
}
324328

0 commit comments

Comments
 (0)