puwaer commited on
Commit
c138be6
·
verified ·
1 Parent(s): 5397fac

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-Q2_K.gguf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ad8f4021d4b1bd89a8d2f339bc2b0675bff9f4718263c220a321c4f1325259a4
3
- size 81409240736
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f8db89823dbaa141009e8c053b62c98a105d99f00b0f500b25f41ed5ddebe87c
3
+ size 81409248512