server : fix OpenAI API stop field to be optional (#4299)

(cherry picked from commit Mozilla-Ocho/llamafile@e8c92bcb84)
This commit is contained in:
Ed Lee 2023-12-03 01:10:43 -08:00 committed by GitHub
parent 6949b50df5
commit 33e171d1e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2410,9 +2410,7 @@ json oaicompat_completion_params_parse(
}
// Handle 'stop' field
if (body["stop"].is_null()) {
llama_params["stop"] = json::array({});
} else if (body["stop"].is_string()) {
if (body.contains("stop") && body["stop"].is_string()) {
llama_params["stop"] = json::array({body["stop"].get<std::string>()});
} else {
llama_params["stop"] = json_value(body, "stop", json::array());