From d643fdd1efe78664ba9d5027ca275899ae22892c Mon Sep 17 00:00:00 2001 From: Reithan Date: Mon, 11 May 2026 15:53:51 -0700 Subject: [PATCH 1/2] fix jinja error on case-insensitive roles and 0-len messages result --- koboldcpp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index 69e096fc0c1..b78218ff08b 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -3510,9 +3510,9 @@ def raise_exception(msg): assist_should_prefill = False chat_template_kwargs = chat_template_kwargs or {} last_assist_msg = "" - if messages: + if len(messages) > 1: 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 if tools and len(tools)>0: From c25d061222030e789439d124468e9a6a4d86a009 Mon Sep 17 00:00:00 2001 From: Reithan Date: Mon, 11 May 2026 16:20:42 -0700 Subject: [PATCH 2/2] check length in correct place --- koboldcpp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/koboldcpp.py b/koboldcpp.py index b78218ff08b..b7ce5681ad2 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -3510,11 +3510,11 @@ def raise_exception(msg): assist_should_prefill = False chat_template_kwargs = chat_template_kwargs or {} last_assist_msg = "" - if len(messages) > 1: + if messages: last_assist_msg = messages[-1]["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: