From ffef7b9cab5161ec2d6d218095cafa5341a8c0ae Mon Sep 17 00:00:00 2001 From: Akarshan Date: Wed, 2 Jul 2025 19:56:07 +0530 Subject: [PATCH] enhancement: Add custom Jinja chat template option Adds a new configuration option `chat_template` to the Llama.cpp extension, allowing users to define a custom Jinja chat template for the model. The template can be provided via a new input field in the settings, and if set, it will be passed to the Llama.cpp backend using the `--chat-template` argument. This enhances flexibility for users who require specific chat formatting beyond the GGUF default. The `chat_template` is added to the `LlamacppConfig` type and conditionally pushed to the command arguments if it's provided. The placeholder text provides an example of a Jinja template structure. --- extensions/llamacpp-extension/settings.json | 12 ++++++++++++ extensions/llamacpp-extension/src/index.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/extensions/llamacpp-extension/settings.json b/extensions/llamacpp-extension/settings.json index 707b50c00..8d013fee1 100644 --- a/extensions/llamacpp-extension/settings.json +++ b/extensions/llamacpp-extension/settings.json @@ -23,6 +23,18 @@ "controllerType": "checkbox", "controllerProps": { "value": true } }, + { + "key": "chat_template", + "title": "Custom Jinja Chat template", + "description": "Custom Jinja chat_template to be used for the model", + "controllerType": "input", + "controllerProps": { + "value": "", + "placeholder": "e.g., {% for message in messages %}...{% endfor %} (default is read from GGUF)", + "type": "text", + "textAlign": "right" + } + }, { "key": "threads", "title": "Threads", diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.ts index e68812510..878c6f4f6 100644 --- a/extensions/llamacpp-extension/src/index.ts +++ b/extensions/llamacpp-extension/src/index.ts @@ -33,6 +33,7 @@ type LlamacppConfig = { version_backend: string auto_update_engine: boolean auto_unload: boolean + chat_template: string n_gpu_layers: number ctx_size: number threads: number @@ -793,6 +794,7 @@ export default class llamacpp_extension extends AIEngine { } // Add remaining options from the interface + if (cfg.chat_template) args.push('--chat-template', cfg.chat_template) args.push('-ngl', String(cfg.n_gpu_layers > 0 ? cfg.n_gpu_layers : 100)) if (cfg.threads > 0) args.push('--threads', String(cfg.threads)) if (cfg.threads_batch > 0)