diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index 96ec86edbc..0605c4ecae 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -1081,18 +1081,7 @@ json convert_responses_to_chatcmpl(const json & body) { const json input_value = body.at("input"); json chatcmpl_messages = json::array(); - if (input_value.is_array()) { - chatcmpl_messages = input_value; - } else if (input_value.is_string()) { - chatcmpl_messages.push_back({ - {"role", "user"}, - {"content", input_value}, - }); - } else { - std::invalid_argument("'input' must be a string or array of objects"); - } - - const std::string instructions = json_value(body, "instructions", std::string{}); + const std::string instructions = json_value(body, "instructions", std::string()); if (instructions != "") { chatcmpl_messages.push_back({ {"role", "system"}, @@ -1100,6 +1089,17 @@ json convert_responses_to_chatcmpl(const json & body) { }); } + if (input_value.is_string()) { + chatcmpl_messages.push_back({ + {"role", "user"}, + {"content", input_value}, + }); + } else if (input_value.is_array()) { + chatcmpl_messages = input_value; + } else { + throw std::invalid_argument("'input' must be a string or array of objects"); + } + json chatcmpl_body = body; chatcmpl_body.erase("input"); chatcmpl_body["messages"] = chatcmpl_messages;