]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : better rwkv chat template and add missing `inputs.use_jinja` setting (#14336)
authorMolly Sophia <redacted>
Mon, 23 Jun 2025 11:56:19 +0000 (19:56 +0800)
committerGitHub <redacted>
Mon, 23 Jun 2025 11:56:19 +0000 (19:56 +0800)
* llama-cli : add missing `inputs.use_jinja` setting

Signed-off-by: Molly Sophia <redacted>
* llama : better legacy chat template for rwkv

Signed-off-by: Molly Sophia <redacted>
---------

Signed-off-by: Molly Sophia <redacted>
src/llama-chat.cpp
tools/main/main.cpp

index 0839cad3ee6db5cea3b883542cee7bb0c9a09a1e..5d317f4ee62ebc0f60d83a805e137de1a24a0ff4 100644 (file)
@@ -528,12 +528,17 @@ int32_t llm_chat_apply_template(
         }
     } else if (tmpl == LLM_CHAT_TEMPLATE_RWKV_WORLD) {
         // this template requires the model to have "\n\n" as EOT token
-        for (auto message : chat) {
-            std::string role(message->role);
-            if (role == "user") {
-                ss << "User: " << message->content << "\n\nAssistant:";
-            } else {
-                ss << message->content << "\n\n";
+        for (size_t i = 0; i < chat.size(); i++) {
+            std::string role(chat[i]->role);
+            if (role == "system") {
+                ss << "System: " << trim(chat[i]->content) << "\n\n";
+            } else if (role == "user") {
+                ss << "User: " << trim(chat[i]->content) << "\n\n";
+                if (i == chat.size() - 1) {
+                    ss << "Assistant:";
+                }
+            } else if (role == "assistant") {
+                ss << "Assistant: " << trim(chat[i]->content) << "\n\n";
             }
         }
     } else if (tmpl == LLM_CHAT_TEMPLATE_GRANITE) {
index 19b247b0d672f9c1874fde92b212bfd832db7a34..154b37cdb01d09b21bb4700fe66444d163faf2d6 100644 (file)
@@ -292,6 +292,7 @@ int main(int argc, char ** argv) {
 
             if (!params.system_prompt.empty() || !params.prompt.empty()) {
                 common_chat_templates_inputs inputs;
+                inputs.use_jinja = g_params->use_jinja;
                 inputs.messages = chat_msgs;
                 inputs.add_generation_prompt = !params.prompt.empty();