Skip to content

Commit 94377d7

Browse files
author
ochafik
committed
server: catch errors in format_final_response_oaicompat instead of taking server down
1 parent 595e11c commit 94377d7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/server/server.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,8 +2879,12 @@ int main(int argc, char ** argv) {
28792879
if (!stream) {
28802880
ctx_server.receive_cmpl_results(task_ids, [&](const std::vector<server_task_result> & results) {
28812881
// multitask is never support in chat completion, there is only one result
2882-
json result_oai = format_final_response_oaicompat(data, results[0].data, completion_id, /*.streaming =*/ false, verbose);
2883-
res_ok(res, result_oai);
2882+
try {
2883+
json result_oai = format_final_response_oaicompat(data, results[0].data, completion_id, /*.streaming =*/ false, verbose);
2884+
res_ok(res, result_oai);
2885+
} catch (const std::runtime_error & e) {
2886+
res_error(res, format_error_response(e.what(), ERROR_TYPE_SERVER));
2887+
}
28842888
}, [&](const json & error_data) {
28852889
res_error(res, error_data);
28862890
});

0 commit comments

Comments
 (0)