]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
cli : Don't clear system prompt when using '/clear' (#20067)
authorRoj234 <redacted>
Fri, 6 Mar 2026 05:41:11 +0000 (13:41 +0800)
committerGitHub <redacted>
Fri, 6 Mar 2026 05:41:11 +0000 (06:41 +0100)
* Enhance /clear command to include system prompt

Add system prompt to messages when clearing chat history.

* Use lambda

tools/cli/cli.cpp

index 65ff4ac6c09de8fe2275757319274b328cdde337..13bedf31ebea5b86def6fa3f4f7b8b9334d8ca50 100644 (file)
@@ -382,12 +382,15 @@ int main(int argc, char ** argv) {
         modalities += ", audio";
     }
 
-    if (!params.system_prompt.empty()) {
-        ctx_cli.messages.push_back({
-            {"role",    "system"},
-            {"content", params.system_prompt}
-        });
-    }
+    auto add_system_prompt = [&]() {
+        if (!params.system_prompt.empty()) {
+            ctx_cli.messages.push_back({
+                {"role",    "system"},
+                {"content", params.system_prompt}
+            });
+        }
+    };
+    add_system_prompt();
 
     console::log("\n");
     console::log("%s\n", LLAMA_ASCII_LOGO);
@@ -477,6 +480,8 @@ int main(int argc, char ** argv) {
             }
         } else if (string_starts_with(buffer, "/clear")) {
             ctx_cli.messages.clear();
+            add_system_prompt();
+
             ctx_cli.input_files.clear();
             console::log("Chat history cleared.\n");
             continue;