add new chat template
This commit is contained in:
parent
9576df906a
commit
b599545e67
2 changed files with 10 additions and 0 deletions
|
@ -12580,6 +12580,15 @@ static int32_t llama_chat_apply_template_internal(
|
||||||
if (add_ass) {
|
if (add_ass) {
|
||||||
ss << "<|assistant|>\n";
|
ss << "<|assistant|>\n";
|
||||||
}
|
}
|
||||||
|
} else if (tmpl.find("bos_token + message['role']") != std::string::npos) {
|
||||||
|
// mlabonne/AlphaMonarch-7B template (the <s> is included inside history)
|
||||||
|
for (auto message : chat) {
|
||||||
|
std::string bos = (message == chat.front()) ? "" : "<s>"; // skip BOS for first message
|
||||||
|
ss << bos << message->role << "\n" << message->content << "</s>\n";
|
||||||
|
}
|
||||||
|
if (add_ass) {
|
||||||
|
ss << "<s>assistant\n";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// template not supported
|
// template not supported
|
||||||
return -1;
|
return -1;
|
||||||
|
|
1
llama.h
1
llama.h
|
@ -708,6 +708,7 @@ extern "C" {
|
||||||
/// Apply chat template. Inspired by hf apply_chat_template() on python.
|
/// Apply chat template. Inspired by hf apply_chat_template() on python.
|
||||||
/// Both "model" and "custom_template" are optional, but at least one is required. "custom_template" has higher precedence than "model"
|
/// Both "model" and "custom_template" are optional, but at least one is required. "custom_template" has higher precedence than "model"
|
||||||
/// NOTE: This function only support some known jinja templates. It is not a jinja parser.
|
/// NOTE: This function only support some known jinja templates. It is not a jinja parser.
|
||||||
|
/// TODO: Add link to docs for this function so that developers can know the list of supported templates
|
||||||
/// @param tmpl A Jinja template to use for this chat. If this is nullptr, the model’s default chat template will be used instead.
|
/// @param tmpl A Jinja template to use for this chat. If this is nullptr, the model’s default chat template will be used instead.
|
||||||
/// @param chat Pointer to a list of multiple llama_chat_message
|
/// @param chat Pointer to a list of multiple llama_chat_message
|
||||||
/// @param n_msg Number of llama_chat_message in this chat
|
/// @param n_msg Number of llama_chat_message in this chat
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue