From edb2ee4d2a533960c1d8a7debfd17e3c68e4a5e6 Mon Sep 17 00:00:00 2001 From: Chao Jiang Date: Sat, 13 Apr 2024 11:38:29 +0800 Subject: [PATCH] Add chat template for command-r model series --- llama.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/llama.cpp b/llama.cpp index 83dd55efa..919ba77d6 100644 --- a/llama.cpp +++ b/llama.cpp @@ -16476,6 +16476,21 @@ static int32_t llama_chat_apply_template_internal( if (add_ass) { ss << "### Response:\n"; } + } else if (tmpl == "command-r" || (tmpl.find("<|START_OF_TURN_TOKEN|>") != std::string::npos && tmpl.find("<|USER_TOKEN|>") != std::string::npos)) { + // CohereForAI/c4ai-command-r-plus + for (auto message : chat) { + std::string role(message->role); + if (role == "system") { + ss << "<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>" << message->content << "<|END_OF_TURN_TOKEN|>"; + } else if (role == "user") { + ss << "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>" << message->content << "<|END_OF_TURN_TOKEN|>"; + } else if (role == "assistant") { + ss << "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>" << message->content << "<|END_OF_TURN_TOKEN|>"; + } + } + if (add_ass) { + ss << "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"; + } } else { // template not supported return -1;