diff options
author | Chao Jiang <jc19chaoj@zoho.com> | 2024-04-15 00:16:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-14 18:16:34 +0200 |
commit | 04fbc5f23e9708136ff03ebe194c7a7e965a7ca4 (patch) | |
tree | 58305b89a192cbe6923f320bea4073838853217f /llama.cpp | |
parent | f184dd920852d6d372b754f871ee06cfe6f977ad (diff) |
Add Command R chat template (#6650)
* Add chat template for command-r model series
* Fix indentation
* Add chat template test for command-r models and update the implementation to trim whitespaces
* Remove debug print
Diffstat (limited to 'llama.cpp')
-rw-r--r-- | llama.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -16625,6 +16625,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|>" << trim(message->content) << "<|END_OF_TURN_TOKEN|>"; + } else if (role == "user") { + ss << "<|START_OF_TURN_TOKEN|><|USER_TOKEN|>" << trim(message->content) << "<|END_OF_TURN_TOKEN|>"; + } else if (role == "assistant") { + ss << "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>" << trim(message->content) << "<|END_OF_TURN_TOKEN|>"; + } + } + if (add_ass) { + ss << "<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"; + } } else { // template not supported return -1; |