Skip to content

Commit 1acee6b

Browse files
authored
server: only parse empty msg if continuing an assistant msg (ggml-org#23506)
1 parent ef570f6 commit 1acee6b

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

common/chat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ struct common_chat_parser_params {
219219
bool reasoning_in_content = false;
220220
std::string generation_prompt;
221221
bool parse_tool_calls = true;
222+
bool is_continuation = false;
222223
bool echo = false; // Include assistant prefilled msg in output
223224
bool debug = false; // Enable debug output for PEG parser
224225
common_peg_arena parser = {};

tools/server/server-task.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ task_result_state::task_result_state(const common_chat_parser_params & chat_pars
149149
, oai_resp_id("resp_" + random_string())
150150
, oai_resp_reasoning_id("rs_" + random_string())
151151
, oai_resp_message_id("msg_" + random_string()) {
152-
if (!chat_parser_params.echo) {
152+
if (chat_parser_params.is_continuation && !chat_parser_params.echo) {
153153
// initialize chat_msg to avoid emitting a delta containing the assistant prefill
154154
chat_msg = common_chat_parse("", true, chat_parser_params);
155155
}
@@ -432,6 +432,10 @@ task_params server_task::params_from_json_cmpl(
432432
if (data.contains("chat_parser")) {
433433
params.chat_parser_params.parser.load(data.at("chat_parser").get<std::string>());
434434
}
435+
if (data.contains("continue_final_message")) {
436+
auto continuation = common_chat_continuation_parse(data.at("continue_final_message"));
437+
params.chat_parser_params.is_continuation = continuation != COMMON_CHAT_CONTINUATION_NONE;
438+
}
435439
params.chat_parser_params.echo = json_value(data, "echo", false);
436440
}
437441

0 commit comments

Comments
 (0)