return raw content if parse failed

This commit is contained in:
Yingbei 2024-03-18 19:31:41 -07:00
parent 9bd7dbb17b
commit 155eeed9ae
No known key found for this signature in database
GPG key ID: 01CC633FE90B97CD

View file

@ -572,14 +572,25 @@ static json format_final_response_oaicompat(const json & request, json result, c
finish_reason = "stop"; finish_reason = "stop";
} }
json choices = json choices;
streaming ? json::array({json{{"finish_reason", finish_reason},
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}, {"index", 0},
{"delta", json::object()}}}) {"message", json{{"content", content},
: json::array({json{{"finish_reason", finish_reason}, {"role", "assistant"}}}}});
} else {
choices = json::array({json{{"finish_reason", finish_reason},
{"index", 0}, {"index", 0},
{"message", json{{"content", parsed_content}, {"message", json{{"content", parsed_content},
{"role", "assistant"}}}}}); {"role", "assistant"}}}}});
}
}
std::time_t t = std::time(0); std::time_t t = std::time(0);