Skip to content

Commit f8b9bb1

Browse files
ggerganovhodlen
authored andcommitted
server : simplify logic for empty prompts (ggml-org#5953)
1 parent 5046025 commit f8b9bb1

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

examples/server/server.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,19 +1704,6 @@ struct server_context {
17041704
// next, batch any pending prompts without exceeding n_batch
17051705
if (params.cont_batching || batch.n_tokens == 0) {
17061706
for (auto & slot : slots) {
1707-
const bool has_prompt = slot.prompt.is_array() || (slot.prompt.is_string() && !slot.prompt.get<std::string>().empty());
1708-
1709-
// empty prompt passed -> release the slot and send empty response
1710-
// note: infill mode allows empty prompt
1711-
if (slot.state == SLOT_STATE_IDLE && slot.command == SLOT_COMMAND_LOAD_PROMPT && !has_prompt && !slot.infill) {
1712-
slot.state = SLOT_STATE_PROCESSING;
1713-
slot.command = SLOT_COMMAND_NONE;
1714-
slot.release();
1715-
slot.print_timings();
1716-
send_final_response(slot);
1717-
continue;
1718-
}
1719-
17201707
// this slot still has a prompt to be processed
17211708
if (slot.state == SLOT_STATE_IDLE && slot.command == SLOT_COMMAND_LOAD_PROMPT) {
17221709
auto & prompt_tokens = slot.prompt_tokens;
@@ -1768,6 +1755,21 @@ struct server_context {
17681755
{"prompt_tokens", tokens_to_str(ctx, prompt_tokens.cbegin(), prompt_tokens.cend())},
17691756
});
17701757

1758+
// empty prompt passed -> release the slot and send empty response
1759+
if (prompt_tokens.empty()) {
1760+
LOG_INFO("empty prompt - releasing slot", {
1761+
{"id_slot", slot.id},
1762+
{"id_task", slot.id_task}
1763+
});
1764+
1765+
slot.state = SLOT_STATE_PROCESSING;
1766+
slot.command = SLOT_COMMAND_NONE;
1767+
slot.release();
1768+
slot.print_timings();
1769+
send_final_response(slot);
1770+
continue;
1771+
}
1772+
17711773
if (slot.embedding) {
17721774
// this prompt is too large to process - discard it
17731775
if (slot.n_prompt_tokens > n_batch) {

0 commit comments

Comments
 (0)