From 155eeed9ae68afcd53b401b00b0b0ee1a5c49600 Mon Sep 17 00:00:00 2001 From: Yingbei Date: Mon, 18 Mar 2024 19:31:41 -0700 Subject: [PATCH] return raw content if parse failed --- examples/server/utils.hpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index fea29c33c..62d04e688 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -572,14 +572,25 @@ static json format_final_response_oaicompat(const json & request, json result, c finish_reason = "stop"; } - json choices = - streaming ? json::array({json{{"finish_reason", finish_reason}, + json choices; + + if (streaming) { + choices = json::array({json{{"finish_reason", finish_reason}, + {"index", 0}, + {"delta", json::object()}}}); + } else { + if (parsed_content.empty()) { + choices = json::array({json{{"finish_reason", finish_reason}, {"index", 0}, - {"delta", json::object()}}}) - : json::array({json{{"finish_reason", finish_reason}, + {"message", json{{"content", content}, + {"role", "assistant"}}}}}); + } else { + choices = json::array({json{{"finish_reason", finish_reason}, {"index", 0}, {"message", json{{"content", parsed_content}, {"role", "assistant"}}}}}); + } + } std::time_t t = std::time(0);