Skip to content

Commit

Permalink
server: catch errors in format_final_response_oaicompat instead of …
Browse files Browse the repository at this point in the history
…taking server down
  • Loading branch information
ochafik committed Sep 26, 2024
1 parent 595e11c commit 94377d7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2879,8 +2879,12 @@ int main(int argc, char ** argv) {
if (!stream) {
ctx_server.receive_cmpl_results(task_ids, [&](const std::vector<server_task_result> & results) {
// multitask is never support in chat completion, there is only one result
json result_oai = format_final_response_oaicompat(data, results[0].data, completion_id, /*.streaming =*/ false, verbose);
res_ok(res, result_oai);
try {
json result_oai = format_final_response_oaicompat(data, results[0].data, completion_id, /*.streaming =*/ false, verbose);
res_ok(res, result_oai);
} catch (const std::runtime_error & e) {
res_error(res, format_error_response(e.what(), ERROR_TYPE_SERVER));
}
}, [&](const json & error_data) {
res_error(res, error_data);
});
Expand Down

0 comments on commit 94377d7

Please sign in to comment.