consolidate gen_chatcmplid()
callsite
This commit is contained in:
parent
aa95dc5568
commit
293378b20b
2 changed files with 5 additions and 5 deletions
|
@ -69,7 +69,7 @@ inline static json oaicompat_completion_params_parse(
|
||||||
return llama_params;
|
return llama_params;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static json format_final_response_oaicompat(const json &request, const task_result &response, bool streaming = false)
|
inline static json format_final_response_oaicompat(const json &request, const task_result &response, std::string id, bool streaming = false)
|
||||||
{
|
{
|
||||||
json result = response.result_json;
|
json result = response.result_json;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ inline static json format_final_response_oaicompat(const json &request, const ta
|
||||||
json{{"completion_tokens", num_tokens_predicted},
|
json{{"completion_tokens", num_tokens_predicted},
|
||||||
{"prompt_tokens", num_prompt_tokens},
|
{"prompt_tokens", num_prompt_tokens},
|
||||||
{"total_tokens", num_tokens_predicted + num_prompt_tokens}}},
|
{"total_tokens", num_tokens_predicted + num_prompt_tokens}}},
|
||||||
{"id", gen_chatcmplid()}};
|
{"id", id}};
|
||||||
|
|
||||||
if (server_verbose) {
|
if (server_verbose) {
|
||||||
res["__verbose"] = result;
|
res["__verbose"] = result;
|
||||||
|
|
|
@ -3221,13 +3221,14 @@ int main(int argc, char **argv)
|
||||||
const int task_id = llama.queue_tasks.get_new_id();
|
const int task_id = llama.queue_tasks.get_new_id();
|
||||||
llama.queue_results.add_waiting_task_id(task_id);
|
llama.queue_results.add_waiting_task_id(task_id);
|
||||||
llama.request_completion(task_id, data, false, false, -1);
|
llama.request_completion(task_id, data, false, false, -1);
|
||||||
|
const std::string completion_id = gen_chatcmplid();
|
||||||
|
|
||||||
if (!json_value(data, "stream", false)) {
|
if (!json_value(data, "stream", false)) {
|
||||||
std::string completion_text;
|
std::string completion_text;
|
||||||
task_result result = llama.queue_results.recv(task_id);
|
task_result result = llama.queue_results.recv(task_id);
|
||||||
|
|
||||||
if (!result.error && result.stop) {
|
if (!result.error && result.stop) {
|
||||||
json oaicompat_result = format_final_response_oaicompat(data, result);
|
json oaicompat_result = format_final_response_oaicompat(data, result, completion_id);
|
||||||
|
|
||||||
res.set_content(oaicompat_result.dump(-1, ' ', false,
|
res.set_content(oaicompat_result.dump(-1, ' ', false,
|
||||||
json::error_handler_t::replace),
|
json::error_handler_t::replace),
|
||||||
|
@ -3238,8 +3239,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
llama.queue_results.remove_waiting_task_id(task_id);
|
llama.queue_results.remove_waiting_task_id(task_id);
|
||||||
} else {
|
} else {
|
||||||
const auto chunked_content_provider = [task_id, &llama](size_t, httplib::DataSink &sink) {
|
const auto chunked_content_provider = [task_id, &llama, completion_id](size_t, httplib::DataSink &sink) {
|
||||||
const std::string completion_id = gen_chatcmplid();
|
|
||||||
while (true) {
|
while (true) {
|
||||||
task_result llama_result = llama.queue_results.recv(task_id);
|
task_result llama_result = llama.queue_results.recv(task_id);
|
||||||
if (!llama_result.error) {
|
if (!llama_result.error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue