summaryrefslogtreecommitdiff
path: root/llama.cpp
diff options
context:
space:
mode:
authorXuan Son Nguyen <thichthat@gmail.com>2024-02-22 19:10:21 +0100
committerGitHub <noreply@github.com>2024-02-22 19:10:21 +0100
commit373ee3fbbabc4c1508eed4f5c3795b23a20939a3 (patch)
tree4b86a6768c8082fe954ef32e1fd119c1da36497d /llama.cpp
parent4cb4d8b22d4fda971621a68c570ce84d66897c37 (diff)
Add Gemma chat template (#5665)
* add gemma chat template * gemma: only apply system_prompt on non-model message
Diffstat (limited to 'llama.cpp')
-rw-r--r--llama.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llama.cpp b/llama.cpp
index 6ab5e1bf..40dda265 100644
--- a/llama.cpp
+++ b/llama.cpp
@@ -12782,6 +12782,28 @@ static int32_t llama_chat_apply_template_internal(
if (add_ass) {
ss << "<s>assistant\n";
}
+ } else if (tmpl.find("<start_of_turn>") != std::string::npos) {
+ // google/gemma-7b-it
+ std::string system_prompt = "";
+ for (auto message : chat) {
+ std::string role(message->role);
+ if (role == "system") {
+ // there is no system message for gemma, but we will merge it with user prompt, so nothing is broken
+ system_prompt = trim(message->content);
+ continue;
+ }
+ // in gemma, "assistant" is "model"
+ role = role == "assistant" ? "model" : message->role;
+ ss << "<start_of_turn>" << role << "\n";
+ if (!system_prompt.empty() && role != "model") {
+ ss << system_prompt << "\n\n";
+ system_prompt = "";
+ }
+ ss << trim(message->content) << "<end_of_turn>\n";
+ }
+ if (add_ass) {
+ ss << "<start_of_turn>model\n";
+ }
} else {
// template not supported
return -1;