puwaer commited on
Commit
a782342
·
verified ·
1 Parent(s): 0f3b89e

Fix chat template: tool calling was broken and, more seriously, so was plain chat once tool support was wired up.

Browse files

What was broken:
- role: "tool" messages raised `unsupported role tool` in the template (reported as "MXFP4_MOE.gguf has wrong chat template").
- No `tools`/`tool_calls` support at all, so OpenAI-compatible clients that check template capabilities refused to forward `tools` (reported as "wrong template - no tool calls available").

What changed:
- Added tool role -> `<tool_result>` merging, `tools` schema rendering, and assistant `tool_calls` -> DSML rendering, ported 1:1 from the base model's `encoding/encoding_dsv4.py` (`merge_tool_messages`, `render_tools`, `encode_arguments_to_dsml`) and verified byte-exact against it over 300+ conversations including tool-call round trips.
- Along the way, fixed a template bug that would have broken *all* chat once tool support triggered llama.cpp's specialized DeepSeek V3.2/V4 response parser: the template never varied its output on `add_generation_prompt`, so llama.cpp's diff-based extraction of the generation prompt came back empty and every completion -- tool call or not -- was rejected as "does not match the expected peg-native format". Fixed by gating the trailing `<|Assistant|>` marker on `add_generation_prompt` only for the final message (mid-conversation transitions before a historical assistant turn stay unconditional, matching the base encoder, which has no such flag).

Verified end to end against a real llama-server (--jinja): plain chat in both thinking modes, a tool-result history round trip, and the model generating its own tool_calls, all succeed.

DeepSeek-V4-Flash-0731-reap-200b-IQ1_M.gguf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2042a78e6c96ec04c2795cac3eceae2bdd7abe4b785bc7464da107bd02c88435
3
- size 60516495008
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b2c4d2539d77e719750afc0333e692da23f77d154f08207244bf9479f4ef3f5
3
+ size 60516502784