From b599545e670525b799bdd2ec4ac6bb384233e61f Mon Sep 17 00:00:00 2001 From: ngxson Date: Wed, 21 Feb 2024 11:12:58 +0100 Subject: [PATCH] add new chat template --- llama.cpp | 9 +++++++++ llama.h | 1 + 2 files changed, 10 insertions(+) diff --git a/llama.cpp b/llama.cpp index 4296eca32..4a3b3b27d 100644 --- a/llama.cpp +++ b/llama.cpp @@ -12580,6 +12580,15 @@ static int32_t llama_chat_apply_template_internal( if (add_ass) { ss << "<|assistant|>\n"; } + } else if (tmpl.find("bos_token + message['role']") != std::string::npos) { + // mlabonne/AlphaMonarch-7B template (the is included inside history) + for (auto message : chat) { + std::string bos = (message == chat.front()) ? "" : ""; // skip BOS for first message + ss << bos << message->role << "\n" << message->content << "\n"; + } + if (add_ass) { + ss << "assistant\n"; + } } else { // template not supported return -1; diff --git a/llama.h b/llama.h index 77a84c18a..cfbbbc02d 100644 --- a/llama.h +++ b/llama.h @@ -708,6 +708,7 @@ extern "C" { /// 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" /// 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 chat Pointer to a list of multiple llama_chat_message /// @param n_msg Number of llama_chat_message in this chat