return true;
}
- void send_partial_response(server_slot & slot, const completion_token_output & tkn, bool is_progress) {
+ void send_partial_response(server_slot & slot, const completion_token_output & tkn, bool is_progress, bool is_begin = false) {
auto res = std::make_unique<server_task_result_cmpl_partial>();
res->id = slot.task->id;
res->progress.cache = slot.n_prompt_tokens_cache;
res->progress.processed = slot.prompt.tokens.size();
res->progress.time_ms = (ggml_time_us() - slot.t_start_process_prompt) / 1000;
+ }
+ if (is_begin) {
+ res->is_begin = true;
} else {
res->content = tkn.text_to_send;
res->tokens = { tkn.tok };
slot.prompt.tokens.keep_first(n_past);
- // send initial 0% progress update if needed
// this is to signal the client that the request has started processing
- if (slot.task->params.stream && slot.task->params.return_progress) {
- send_partial_response(slot, {}, true);
+ if (slot.task->params.stream) {
+ if (slot.task->params.return_progress) {
+ // send initial 0% progress update if needed
+ send_partial_response(slot, {}, true);
+ } else {
+ // otherwise, for streaming without progress, signal HTTP to send the headers (i.e. 200 status)
+ send_partial_response(slot, {}, false, true);
+ }
}
}
// next responses are streamed
// to be sent immediately
json first_result_json = first_result->to_json();
- if (res_type == TASK_RESPONSE_TYPE_ANTHROPIC) {
+ if (first_result_json == nullptr) {
+ res->data = ""; // simply send HTTP headers and status code
+ } else if (res_type == TASK_RESPONSE_TYPE_ANTHROPIC) {
res->data = format_anthropic_sse(first_result_json);
} else if (res_type == TASK_RESPONSE_TYPE_OAI_RESP) {
res->data = format_oai_resp_sse(first_result_json);
};
struct task_params {
- bool stream = true;
+ bool stream = false;
bool include_usage = false;
bool cache_prompt = true; // remember the prompt to avoid reprocessing all prompt
bool return_tokens = false;
bool post_sampling_probs;
bool is_progress = false;
+ bool is_begin = false; // whether to send 200 status to HTTP client (begin of SSE stream)
+ // ref: https://github.com/ggml-org/llama.cpp/pull/23884
completion_token_output prob_output;
result_timings timings;
result_prompt_progress progress;