From 7cbeb4e2a51aa5143200d7b705515c0d3ef6135f Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Mon, 11 Aug 2025 15:16:06 +0200 Subject: [PATCH 1/2] chat : hotfix gpt-oss jinja raising an exception --- common/chat.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/chat.cpp b/common/chat.cpp index 92fbbbe111f01..4cb4d41096515 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -552,6 +552,17 @@ common_chat_templates_ptr common_chat_templates_init( default_template_src = CHATML_TEMPLATE_SRC; } } + + // TODO @ngxson : this is a temporary hack to prevent chat template from throwing an error + // Ref: https://github.com/ggml-org/llama.cpp/pull/15230#issuecomment-3173959633 + if (default_template_src.find("<|channel|>") != std::string::npos + // search for the error message and patch it + && default_template_src.find("in message.thinking") != std::string::npos) { + string_replace_all(default_template_src, + "{%- if \"<|channel|>analysis<|message|>\" in message.thinking or \"<|channel|>final<|message|>\" in message.thinking %}", + "{%- if false %}"); + } + std::string token_bos = bos_token_override; std::string token_eos = eos_token_override; bool add_bos = false; From 94d8042eb858b0eab4c2634000eb67c324c4ba7e Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Mon, 11 Aug 2025 15:25:33 +0200 Subject: [PATCH 2/2] fix --- common/chat.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/chat.cpp b/common/chat.cpp index 4cb4d41096515..b1a1218ca2c97 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -557,9 +557,9 @@ common_chat_templates_ptr common_chat_templates_init( // Ref: https://github.com/ggml-org/llama.cpp/pull/15230#issuecomment-3173959633 if (default_template_src.find("<|channel|>") != std::string::npos // search for the error message and patch it - && default_template_src.find("in message.thinking") != std::string::npos) { + && default_template_src.find("in message.content or") != std::string::npos) { string_replace_all(default_template_src, - "{%- if \"<|channel|>analysis<|message|>\" in message.thinking or \"<|channel|>final<|message|>\" in message.thinking %}", + "{%- if \"<|channel|>analysis<|message|>\" in message.content or \"<|channel|>final<|message|>\" in message.content %}", "{%- if false %}"); }