From a601da6fd4d92aff171554439c0ca3ba91dae53f Mon Sep 17 00:00:00 2001 From: ngxson Date: Mon, 11 Mar 2024 22:14:27 +0100 Subject: [PATCH] specify types --- examples/server/server.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/server/server.cpp b/examples/server/server.cpp index 2ff3d9588..d698be76a 100644 --- a/examples/server/server.cpp +++ b/examples/server/server.cpp @@ -3373,40 +3373,39 @@ int main(int argc, char ** argv) { bool is_openai = false; // an input prompt can be a string or a list of tokens (integer) - json prompts = json::array(); + json prompt; if (body.count("input") != 0) { is_openai = true; - prompts = body["input"].is_array() - ? body["input"] // support multiple prompts - : json{body["input"]}; // single input prompt + prompt = body["input"]; } else if (body.count("content") != 0) { // with "content", we only support single prompt - std::string content = body["content"]; - prompts.push_back(content); + prompt = std::vector{body["content"]}; } else { res_error(res, format_error_response("\"input\" or \"content\" must be provided", ERROR_TYPE_INVALID_REQUEST)); return; } // create and queue the task - json responses = json::array(); + json responses; { const int id_task = ctx_server.queue_tasks.get_new_id(); ctx_server.queue_results.add_waiting_task_id(id_task); - // if number of prompts is more than 1, we pass an array to create a multi-task - // otherwise, we pass a single prompt to make a single task ctx_server.request_completion(id_task, -1, { - {"prompt", prompts.size() == 1 ? prompts[0] : prompts}, - {"n_predict", 0} + {"prompt", prompt}, + {"n_predict", 0}, }, false, true); // get the result server_task_result result = ctx_server.queue_results.recv(id_task); ctx_server.queue_results.remove_waiting_task_id(id_task); if (!result.error) { - responses = result.data.count("results") - ? result.data["results"] // result for multi-task - : json{result.data}; // result for single task + if (result.data.count("results")) { + // result for multi-task + responses = result.data["results"]; + } else { + // result for single task + responses = std::vector{result.data}; + } } else { // error received, ignore everything else res_error(res, result.data);