feat: add DeepSeek V4 Flash 0731 renderer - #140
Conversation
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This change adds a substantial production renderer and parser for DeepSeek V4, including new thinking, tool-calling, token-attribution, and turn-bridging behavior. Its scope and runtime protocol impact exceed a small bounded addition and merit human review. Notes:
You can add or adjust custom eligibility rules. Learn more. |
10e421b to
b28c91f
Compare
garrett361
left a comment
There was a problem hiding this comment.
Thank you @hallerite ! This all looks reasonable to me, but probably someone who is more familiar w/ renderers should give the approval
| reasoning_effort: Literal["low", "high", "max"] = "low" | ||
| """Thinking-only effort prefix; ``low`` adds no text.""" |
There was a problem hiding this comment.
Little confusing about what the intended default is: "high" https://api-docs.deepseek.com/guides/thinking_mode/ seems to say "high" is the intended default, but I see it's None = low in the hf impl https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash/blob/main/encoding/encoding_dsv4.py#L222
There was a problem hiding this comment.
imo the default should be low, as we are matching against the deepseek encoder, while high being the default on the API is a service-level policy
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a7217e5. Configure here.

Summary
Validation
Official encoder: https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash-0731/blob/main/encoding/encoding_dsv4.py
Note
Add
DeepSeekV4Rendererfor DeepSeek V4 Flash 0731DeepSeekV4RendererandDeepSeekV4RendererConfigto support thedeepseek-ai/DeepSeek-V4-Flash-0731model, which uses DSML wire format instead of a tokenizer chat template.parse_deepseek_v4to decode model outputs into content, reasoning, and structured DSML tool calls in parsing.py.tokenizer.apply_chat_templatein test parity checks.DeepSeekV4RendererConfigdefaults toenable_thinking=False,drop_thinking=True, andreasoning_effort='low'.Changes since #140 opened
_QUERY_ROLESfrozenset constant containing 'user' and 'developer', added_is_query_messagehelper function, and updatedrenderers.deepseek_v4.DeepSeekV4Renderer.render_idsto replace hardcoded role checks with_QUERY_ROLESwhen computing the last query boundary index, filtering historical developer and search-agent messages during thinking drops, determining reasoning retention for assistant messages, and opening new reasoning segments [98cb612]renderers.deepseek_v4.DeepSeekV4Renderer.bridge_to_next_turnto passis_user_query=_is_query_messagepredicate toshould_rerender_for_thinking_retentionmethod [98cb612]test_bridge_declines_at_developer_query_boundary_when_dropping_thinkingandtest_bridge_extends_developer_query_when_preserving_all_thinkingintests.test_deepseek_v4module [98cb612]Macroscope summarized a7217e5.
Note
Medium Risk
New ~860-line renderer on the critical prompt/tokenization path with complex thinking, tool, and bridge semantics; mistakes would skew training/inference token streams for V4, though coverage is extensive and defaults match the official encoder.
Overview
Adds first-class support for
deepseek-ai/DeepSeek-V4-Flash-0731, which has no Jinja chat template and instead follows the model repo’s Pythonencoding_dsv4.pycontract.DeepSeekV4RendererandDeepSeekV4RendererConfigimplement that encoder in the renderer protocol: chat vs thinking mode, optional reasoning-effort prefixes, historical reasoning drop (disabled when tools are present), DSML tool schemas/calls, mergedtoolresults with call-order sorting, task tokens, response-format blocks,parse_deepseek_v4for completions, andbridge_to_next_turnwith thinking-retention rules. Prompt text is tokenized in one BPE pass so token IDs match the reference encoder across fragment boundaries.Registration wires the checkpoint to
deepseek-v4viaMODEL_RENDERER_MAP, lazy exports, and the typed config union; README anddocs/renderer-config.mddocument the new family.Tests add
tests/reference_rendering.render_referenceso shared parity usesapply_chat_templatefor Jinja models and an independent V4 mirror for barrage/bridge/config-matrix coverage, plustests/test_deepseek_v4.pyfor encoder edge cases.Reviewed by Cursor Bugbot for commit 98cb612. Bugbot is set up for automated code reviews on this repo. Configure here.