Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Update chat_templates.py

Daniel Han-Chen08d22b885343
diff --git a/unsloth/chat_templates.py b/unsloth/chat_templates.py
index 026e6dbad78..ee58ca2b831 100644
--- a/unsloth/chat_templates.py
+++ b/unsloth/chat_templates.py
@@ -789,7 +789,7 @@ def _create_formatter(possible_columns, final_optional_prompts, user_column_name
prompt = prompt[2:-2].encode("unicode-escape").decode("utf-8")
columns = re.findall(r"\{(.+?)\}", prompt)
x = f"__optional_{j}__"
- prompt = f"{' '*8}{x} = '{prompt}'.format({', '.join(f'{x} = {x}' for x in columns)}) if {x} else ''"
+ prompt = f"{' '*8}{x} = '{prompt}'.format({', '.join(f'{x} = {x}' for x in columns)}) if {columns[0]} else ''"
function.append(prompt)
formatter.append(x)
final_prompt += "{" + x + "}"