From be5b283153349db74f6a9c1af50830b953eafbe5 Mon Sep 17 00:00:00 2001 From: Ryan Goulden Date: Wed, 1 Jul 2026 05:21:32 -0700 Subject: [PATCH] llama-completion: respect chat_template_kwargs and reasoning_format params --- common/arg.cpp | 2 +- tools/completion/completion.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/arg.cpp b/common/arg.cpp index 772422f6820a..305b43f9d327 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -3432,7 +3432,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex params.default_template_kwargs[item.key()] = item.value().dump(); } } - ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_CHAT_TEMPLATE_KWARGS")); + ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_CHAT_TEMPLATE_KWARGS")); add_opt(common_arg( {"-to", "--timeout"}, "N", string_format("server read/write timeout in seconds (default: %d)", params.timeout_read), diff --git a/tools/completion/completion.cpp b/tools/completion/completion.cpp index 6747558fc543..c508bae386ef 100644 --- a/tools/completion/completion.cpp +++ b/tools/completion/completion.cpp @@ -156,6 +156,7 @@ int llama_completion(int argc, char ** argv) { // note: the time for chat template initialization is not negligible: auto chat_templates = common_chat_templates_init(model, params.chat_template); + const bool template_supports_thinking = params.use_jinja && common_chat_templates_support_enable_thinking(chat_templates.get()); // start measuring performance timings from here llama_perf_context_reset(ctx); @@ -303,9 +304,12 @@ int llama_completion(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(); + inputs.use_jinja = params.use_jinja; + inputs.reasoning_format = params.reasoning_format; + inputs.enable_thinking = params.enable_reasoning != 0 && template_supports_thinking; + inputs.chat_template_kwargs = params.default_template_kwargs; inputs.force_pure_content = params.force_pure_content_parser; prompt = common_chat_templates_apply(chat_templates.get(), inputs).prompt;