This commit is contained in:
yq-pan 2024-04-30 09:14:09 -04:00 committed by GitHub
commit bd7a95e799
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View file

@ -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|>", "</s>"});
}
// Handle "response_format" field
if (body.contains("response_format")) {
json response_format = json_value(body, "response_format", json::object());

View file

@ -17749,6 +17749,42 @@ static int32_t llama_chat_apply_template_internal(
if (add_ass) {
ss << "<|assistant|>\n";
}
} else if (tmpl == "minicpm" || (tmpl.find("<用户>") != std::string::npos && tmpl.find("<AI>") != std::string::npos )) {
for (auto message : chat) {
std::string role(message->role);
if (role == "user"){
ss << "<用户>: " << trim(message->content) << "\n";
}else{
ss << "<AI>: " << trim(message->content) << "\n";
}
}
if (add_ass) {
ss << "\n<AI>: ";
}
}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;