mistral_common.integrations.hf_tokenizers.response_template
ThinkingMode
Bases: StrEnum
How the model encodes thinking in assistant messages.
Attributes:
| Name | Type | Description |
|---|---|---|
none |
No thinking support. |
|
special |
[THINK]/[/THINK] special tokens (v13+). |
|
plain |
Plain |
convert_tokenizer_to_response_template(tokenizer, plain_thinking_support)
Generate the Hugging Face response template for a loaded MistralTokenizer.
Special-token thinking is detected from the tokenizer's special tokens.
Plain thinking cannot be reliably detected: reasoning and non-reasoning
v11 models can have identical tokenizer files, so when
plain_thinking_support is None the same heuristic as
convert_tokenizer_to_chat_template applies (v11 without audio).
See https://huggingface.co/docs/transformers/en/chat_response_parsing for the Transformers response parsing schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer
|
MistralTokenizer
|
An already-loaded |
required |
plain_thinking_support
|
bool | None
|
Whether to emit plain-thinking parsing for v11,
or |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A JSON-serializable mapping suitable for a tokenizer configuration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If plain thinking is requested for a non-v11 tokenizer or one with audio support. |
Source code in src/mistral_common/integrations/hf_tokenizers/response_template.py
generate_response_template(tokenizer_version, thinking_mode)
Generate the Hugging Face response_template mapping.
See https://huggingface.co/docs/transformers/en/chat_response_parsing for the Transformers response parsing schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokenizer_version
|
TokenizerVersion
|
Tokenizer version used to select field formats. |
required |
thinking_mode
|
ThinkingMode
|
Thinking encoding to emit; must be compatible with the version.
Note the audio-compatibility rule for |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A JSON-serializable mapping suitable for a tokenizer configuration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> generate_response_template(
... tokenizer_version=TokenizerVersion.v13,
... thinking_mode=ThinkingMode.special,
... )["defaults"]
{'role': 'assistant'}