Skip to content

Conversation

@soaringk
Copy link
Collaborator

@soaringk soaringk commented Dec 2, 2025

DeepSeek-V3.2 introduces significant updates to its chat template compared to prior versions. The primary changes involve a revised format for tool calling and the introduction of a "thinking with tools" capability.

To assist the community in understanding and adapting to this new template, we have provided a dedicated encoding folder, which contains Python scripts and test cases demonstrating how to encode messages in OpenAI-compatible format into input strings for the model and how to parse the model's text output.

A brief example is illustrated below:

import transformers
# encoding/encoding_dsv32.py
from encoding_dsv32 import encode_messages, parse_message_from_completion_text

tokenizer = transformers.AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-V3.2")

messages = [
    {"role": "user", "content": "hello"},
    {"role": "assistant", "content": "Hello! I am DeepSeek.", "reasoning_content": "thinking..."},
    {"role": "user", "content": "1+1=?"}
]
encode_config = dict(thinking_mode="thinking", drop_thinking=True, add_default_bos_token=True)

# messages -> string
prompt = encode_messages(messages, **encode_config)
# Output: "<|begin▁of▁sentence|><|User|>hello<|Assistant|></think>Hello! I am DeepSeek.<|end▁of▁sentence|><|User|>1+1=?<|Assistant|><think>"

# string -> tokens
tokens = tokenizer.encode(prompt)
# Output: [0, 128803, 33310, 128804, 128799, 19923, 3, 342, 1030, 22651, 4374, 1465, 16, 1, 128803, 19, 13, 19, 127252, 128804, 128798]

Important Notes:

This release does not include a Jinja-format chat template. Please refer to the Python code mentioned above.
The output parsing function included in the code is designed to handle well-formatted strings only. It does not attempt to correct or recover from malformed output that the model might occasionally generate. It is not suitable for production use without robust error handling.
A new role named developer has been introduced in the chat template. This role is dedicated exclusively to search agent scenarios and is designated for no other tasks. The official API does not accept messages assigned to developer.

Reference: https://huggingface.co/deepseek-ai/DeepSeek-V3.2

@soaringk soaringk requested a review from LLLLKKKK as a code owner December 2, 2025 05:15
@soaringk soaringk changed the base branch from main to release/0.2.0 December 2, 2025 05:37
@soaringk soaringk changed the base branch from release/0.2.0 to main December 2, 2025 05:41
@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 5 times, most recently from db99b6e to c36b3f7 Compare December 2, 2025 08:43
@github-actions
Copy link

github-actions bot commented Dec 2, 2025

internal source has been updated, please review the changes!

1 similar comment
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from 192b403 to 2a4a143 Compare December 3, 2025 06:53
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from 12c1b72 to 98a7500 Compare December 4, 2025 09:10
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 3 times, most recently from d78bef5 to 1413c45 Compare December 6, 2025 07:10
@github-actions
Copy link

github-actions bot commented Dec 6, 2025

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 2 times, most recently from c02d23c to c513694 Compare December 10, 2025 09:41
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from c513694 to 1c97338 Compare December 10, 2025 13:30
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 2 times, most recently from 16b943b to 2ed31b5 Compare December 11, 2025 03:26
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 3 times, most recently from 14e6e0c to 338bf6b Compare December 15, 2025 04:21
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 3 times, most recently from 8637143 to 93ccbd9 Compare December 18, 2025 07:34
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 2 times, most recently from 4bd4339 to 02fffc8 Compare December 18, 2025 11:47
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from 02fffc8 to eb72107 Compare December 19, 2025 02:24
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from eb72107 to ca14b13 Compare December 20, 2025 17:37
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from ca14b13 to ca09274 Compare December 23, 2025 10:05
@github-actions
Copy link

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 2 times, most recently from 7341eee to f61910e Compare December 23, 2025 13:14
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

internal source has been updated, please review the changes!

2 similar comments
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

internal source has been updated, please review the changes!

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from 0adcd45 to 4aebc77 Compare January 5, 2026 06:09
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from 4aebc77 to 8c51b6e Compare January 5, 2026 11:42
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

internal source has been updated, please review the changes!

@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch 2 times, most recently from 36ef3b4 to 4c52d4b Compare January 5, 2026 13:28
@soaringk soaringk force-pushed the feature/adopt-ds-v3.2-encode branch from 4c52d4b to 314e1fc Compare January 6, 2026 07:22
@LLLLKKKK LLLLKKKK merged commit 4bc4d3a into main Jan 6, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants