add minicpm chat template
This commit is contained in:
parent
b8c1476e44
commit
b8aec23086
2 changed files with 41 additions and 1 deletions
|
@ -382,6 +382,10 @@ static json oaicompat_completion_params_parse(
|
||||||
llama_params["stop"] = json_value(body, "stop", json::array());
|
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
|
// Handle "response_format" field
|
||||||
if (body.contains("response_format")) {
|
if (body.contains("response_format")) {
|
||||||
json response_format = json_value(body, "response_format", json::object());
|
json response_format = json_value(body, "response_format", json::object());
|
||||||
|
|
38
llama.cpp
38
llama.cpp
|
@ -17579,7 +17579,43 @@ static int32_t llama_chat_apply_template_internal(
|
||||||
if (add_ass) {
|
if (add_ass) {
|
||||||
ss << "<|assistant|>\n";
|
ss << "<|assistant|>\n";
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
// template not supported
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue