From b2cf6e73fc9e54929c3f0e5019026b7ab9e29625 Mon Sep 17 00:00:00 2001 From: MaggotHATE Date: Thu, 21 Nov 2024 22:26:06 +0500 Subject: [PATCH] Fixed prefix and suffix compatibility * if payload contains empty prefix or suffix, use arguments instead --- examples/server/utils.hpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index d82bc6464..1d89a8262 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -636,17 +636,24 @@ static json oaicompat_completion_params_parse( llama_params["__oaicompat"] = true; // Apply chat template to the list of messages - std::string chat_tmpl = chat_template; - std::string prefix = ""; - std::string suffix = ""; + std::string chat_tmpl = (body.contains("chat_template") ? body.at("chat_template").get() : chat_template); + std::string prefix = (body.contains("input_prefix") ? body.at("input_prefix").get() : ""); + std::string suffix = (body.contains("input_suffix") ? body.at("input_suffix").get() : ""); // if template is sent in data, ignore prefix and suffix - if (body.contains("chat_template")) { - chat_tmpl = body.at("chat_template").get(); + if (!chat_tmpl.empty()) { LOG_WRN("\nUsing '%s' template, prefix and suffix are ignored.\n", chat_tmpl.c_str()); + prefix = ""; + suffix = ""; } else { - prefix = (body.contains("input_prefix") ? body.at("input_prefix").get() : input_prefix); - suffix = (body.contains("input_suffix") ? body.at("input_suffix").get() : input_suffix); + if (prefix.empty()) { + prefix = input_prefix; + } + + if (suffix.empty()) { + suffix = input_suffix; + } + LOG_WRN("\nUsing prefix '%s' and suffix '%s'.\n", prefix.c_str(), suffix.c_str()); } llama_params["prompt"] = format_chat(model, chat_tmpl, prefix, suffix, body.at("messages"));