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 // Handle 'stop' field
if (body["stop"].is_null()) { if (body.contains("stop") && body["stop"].is_string()) {
llama_params["stop"] = json::array({});
} else if (body["stop"].is_string()) {
llama_params["stop"] = json::array({body["stop"].get<std::string>()}); llama_params["stop"] = json::array({body["stop"].get<std::string>()});
} else { } else {
llama_params["stop"] = json_value(body, "stop", json::array()); llama_params["stop"] = json_value(body, "stop", json::array());