Fix chat template: port upstream GLM-5.3-Flash fix 690b705

#1
by wangrichard08 - opened

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

  1. None leaking into the prompt. visible_text() fell through to {{- content }} even when content was None, so an assistant message with content: null (the normal shape for a tool-call-only turn) rendered a literal None into the prompt. Now guarded with {%- elif content is not none -%}, and the whitespace control is balanced ({{- content -}}).

  2. + vs ~ on the tool-call name. '<tool_call>' + tc.name raises a Jinja TypeError if tc.name is not a string; ~ coerces instead.

  3. 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.

  4. Missing breaks. Four early exits added so the can_sort scans stop once a duplicate/missing ID has already disqualified sorting, instead of running the full O(n²) scan.

Verification

  • git apply of the upstream diff onto this repo's chat_template.jinja → clean, and git hash-object on the result matches upstream's post-fix blob exactly.
  • Rendered with Jinja2 (loopcontrols extension, as transformers enables) across plain chat, a content: null assistant turn with tool calls, and duplicate tool-call IDs — all render without error.
  • Before/after on the content: null case:
    • before: ...<|assistant|><think></think>None\n<tool_call>get_weather...
    • after: ...<|assistant|><think></think>\n<tool_call>get_weather...
mmangkad changed pull request status to merged
mmangkad deleted the refs/pr/1 ref

Sign up or log in to comment