Fix chat template: port upstream GLM-5.3-Flash fix 690b705
Ports the chat-template fix from upstream zai-org/GLM-5.3-Flash, commit 690b705.
chat_template.jinja in this repo was byte-identical to upstream's pre-fix version (blob fb94d40d), so the upstream patch applies cleanly; the result is byte-identical to upstream's fixed version (blob 06bd89e9). No NVFP4-specific customizations were touched.
What the upstream commit fixes
Noneleaking into the prompt.visible_text()fell through to{{- content }}even whencontentwasNone, so an assistant message withcontent: null(the normal shape for a tool-call-only turn) rendered a literalNoneinto the prompt. Now guarded with{%- elif content is not none -%}, and the whitespace control is balanced ({{- content -}}).+vs~on the tool-call name.'<tool_call>' + tc.nameraises a JinjaTypeErroriftc.nameis not a string;~coerces instead.Broken loop nesting in the tool-call sort check. The
{%- endfor -%}/{%- else -%}pair closing the tool-call ID scan was mis-indented and mis-scoped; the commit re-nests them correctly.Missing
breaks. Four early exits added so thecan_sortscans stop once a duplicate/missing ID has already disqualified sorting, instead of running the full O(n²) scan.
Verification
git applyof the upstream diff onto this repo'schat_template.jinja→ clean, andgit hash-objecton the result matches upstream's post-fix blob exactly.- Rendered with Jinja2 (
loopcontrolsextension, astransformersenables) across plain chat, acontent: nullassistant turn with tool calls, and duplicate tool-call IDs — all render without error. - Before/after on the
content: nullcase:- before:
...<|assistant|><think></think>None\n<tool_call>get_weather... - after:
...<|assistant|><think></think>\n<tool_call>get_weather...
- before:
refs/pr/1 ref