From 5962bca463ffc3074bdaaab7b66544c1584870e1 Mon Sep 17 00:00:00 2001 From: Reithan Date: Fri, 15 May 2026 01:48:42 -0700 Subject: [PATCH] Fix jinja error on case-insensitive roles and 0-len messages result (#2201) * fix jinja error on case-insensitive roles and 0-len messages result * check length in correct place --- koboldcpp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index d79d7f4cd..af13c8633 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -3584,9 +3584,9 @@ def format_jinja(messages_orig, tools, chat_template_kwargs=None): last_assist_msg = "" if messages: last_assist_msg = messages[-1]["content"] - assist_should_prefill = (messages and messages[-1]["role"] == "assistant" and last_assist_msg and isinstance(last_assist_msg, str) and len(last_assist_msg.strip())>0) #avoid single character newline or space content + assist_should_prefill = (messages and messages[-1]["role"].lower() == "assistant" and last_assist_msg and isinstance(last_assist_msg, str) and len(last_assist_msg.strip())>0) #avoid single character newline or space content last_assist_msg = "" if not assist_should_prefill else last_assist_msg - messages_for_render = messages[:-1] if assist_should_prefill else messages + messages_for_render = messages[:-1] if len(messages) > 1 and assist_should_prefill else messages if tools and len(tools)>0: text = jinja_compiled_template.render(messages=messages_for_render, tools=tools, add_generation_prompt=True, bos_token="", eos_token="", **chat_template_kwargs) else: