diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index 1a2212502..50c3f661c 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -382,6 +382,10 @@ static json oaicompat_completion_params_parse( llama_params["stop"] = json_value(body, "stop", json::array()); } + if( chat_template.find("minicpm") != std::string::npos){ + llama_params["stop"].insert(llama_params["stop"].end(), {"<|im_end|>", ""}); + } + // Handle "response_format" field if (body.contains("response_format")) { json response_format = json_value(body, "response_format", json::object()); diff --git a/llama.cpp b/llama.cpp index 72c10ffc2..fb3a213ae 100644 --- a/llama.cpp +++ b/llama.cpp @@ -17579,7 +17579,43 @@ static int32_t llama_chat_apply_template_internal( if (add_ass) { ss << "<|assistant|>\n"; } - } else { + } else if (tmpl == "minicpm" || (tmpl.find("<用户>") != std::string::npos && tmpl.find("") != std::string::npos )) { + + for (auto message : chat) { + std::string role(message->role); + if (role == "user"){ + ss << "<用户>: " << trim(message->content) << "\n"; + }else{ + ss << ": " << trim(message->content) << "\n"; + } + } + if (add_ass) { + ss << "\n: "; + } + }else if (tmpl == "minicpm-128k" || tmpl.find("<|im_start|>") != std::string::npos) { + // chatml template + std::string tmp = ""; + for (auto message : chat) { + std::string role(message->role); + std::string content(message->content); + //remove system ... + if (message->role == "system"){ + role = "user"; + tmp = message->content; + continue; + } + + if(role == "user" && tmp !=""){ + content =tmp+"\n\n"+ message->content; + tmp = ""; + } + + ss << "<|im_start|>" << role << "\n" << content << "<|im_end|>\n"; + } + if (add_ass) { + ss << "<|im_start|>assistant\n"; + } + }else { // template not supported return -1; }