server : indentation

This commit is contained in:
Georgi Gerganov 2023-11-24 11:00:15 +02:00
parent 80724eb0e1
commit b94b10914c
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735

View File

@ -2678,38 +2678,38 @@ int main(int argc, char **argv)
} else { } else {
const auto chunked_content_provider = [task_id, &llama](size_t, httplib::DataSink &sink) { const auto chunked_content_provider = [task_id, &llama](size_t, httplib::DataSink &sink) {
while (true) { while (true) {
task_result llama_result = llama.next_result(task_id); task_result llama_result = llama.next_result(task_id);
if (!llama_result.error) { if (!llama_result.error) {
std::vector<json> result_array = format_partial_response_oaicompat( llama_result); std::vector<json> result_array = format_partial_response_oaicompat( llama_result);
for (auto it = result_array.begin(); it != result_array.end(); ++it) for (auto it = result_array.begin(); it != result_array.end(); ++it)
{ {
if (!it->empty()) { if (!it->empty()) {
const std::string str = const std::string str =
"data: " + "data: " +
it->dump(-1, ' ', false, json::error_handler_t::replace) + it->dump(-1, ' ', false, json::error_handler_t::replace) +
"\n\n"; "\n\n";
LOG_VERBOSE("data stream", {{"to_send", str}}); LOG_VERBOSE("data stream", {{"to_send", str}});
if (!sink.write(str.c_str(), str.size())) { if (!sink.write(str.c_str(), str.size())) {
return false; return false;
}
} }
} }
} if (llama_result.stop) {
if (llama_result.stop) { break;
}
} else {
const std::string str =
"error: " +
llama_result.result_json.dump(-1, ' ', false,
json::error_handler_t::replace) +
"\n\n";
LOG_VERBOSE("data stream", {{"to_send", str}});
if (!sink.write(str.c_str(), str.size())) {
return false;
}
break; break;
} }
} else {
const std::string str =
"error: " +
llama_result.result_json.dump(-1, ' ', false,
json::error_handler_t::replace) +
"\n\n";
LOG_VERBOSE("data stream", {{"to_send", str}});
if (!sink.write(str.c_str(), str.size())) {
return false;
}
break;
}
} }
sink.done(); sink.done();
return true; return true;