nathanrchn commited on
Commit
0995a84
·
verified ·
1 Parent(s): 13a5383

Fix chat template: render assistant tool_calls

Browse files

Assistant messages carrying `tool_calls` render to nothing under the current
template: the message loop ends in a single `{{- content + "<|im_end|>\n" -}}`
with no branch for tool calls. Two consequences, both reproduced on
llama.cpp `server-rocm-b10088`:

1. llama.cpp probes the template at startup, sees that a tool call renders to
nothing, and reports `supports_tool_calls: false` /
`supports_parallel_tool_calls: false` in `/props`. It then constrains
generation to at most one call, so the second call of a parallel request is
never sampled.
2. Replaying a conversation that already contains an assistant tool call
produces an empty assistant turn, while the following `tool` result is still
rendered -- the model sees an answer to a question it has no record of asking.

**This PR** adds the `format_arg_value` / `render_tool_calls` macros (taken
verbatim from the latest LFM2.5 template) and one branch that emits them, so a
tool call renders as
`<|tool_call_start|>[name(arg='value'), ...]<|tool_call_end|>`.
It also changes `message["content"]` to `message.get("content")`: an assistant
message with `tool_calls` and no `content` key -- the ordinary OpenAI-style
payload -- otherwise raises
`TypeError: Object of type Undefined is not JSON serializable`.

Nothing else changes. The tool-marker convention, thinking handling and
formatting are untouched, and a conversation without tools renders
byte-identically to the current template.

**Verified** on llama.cpp: `chat_template_caps` goes false -> true, parallel
tool calls 1 -> 2, and the replayed assistant turn is preserved. transformers
and minja render identically. Benchmark runs (IFBench, MATH-500, GPQA Diamond,
AA-Omniscience, BFCL v4 multiple/multi_turn_base/irrelevance) are in flight;
please hold merge until those confirm no regression.

1 file changed +37 -29
chat_template.jinja+37-29