bridge.models.deepseek.data.encoding_v4#

DeepSeek-V4 conversation encoding for SFT.

This module implements the public encoding contract released with deepseek-ai/DeepSeek-V4-Flash and DeepSeek-V4-Pro. The upstream model repository is MIT licensed; this implementation is adapted to Bridge’s typing, validation, and OpenAI-style dataset contracts.

Module Contents#

Functions#

Data#

API#

bridge.models.deepseek.data.encoding_v4.BOS_TOKEN#

‘<|begin▁of▁sentence|>’

bridge.models.deepseek.data.encoding_v4.EOS_TOKEN#

‘<|end▁of▁sentence|>’

bridge.models.deepseek.data.encoding_v4.THINKING_START_TOKEN#

bridge.models.deepseek.data.encoding_v4.THINKING_END_TOKEN#

‘’

bridge.models.deepseek.data.encoding_v4.DSML_TOKEN#

‘|DSML|’

bridge.models.deepseek.data.encoding_v4.USER_TOKEN#

‘<|User|>’

bridge.models.deepseek.data.encoding_v4.ASSISTANT_TOKEN#

‘<|Assistant|>’

bridge.models.deepseek.data.encoding_v4.LATEST_REMINDER_TOKEN#

‘<|latest_reminder|>’

bridge.models.deepseek.data.encoding_v4._TASK_TOKENS#

None

bridge.models.deepseek.data.encoding_v4._TOOL_CALLS_BLOCK_NAME#

‘tool_calls’

bridge.models.deepseek.data.encoding_v4._REASONING_EFFORT_MAX = <Multiline-String>#
bridge.models.deepseek.data.encoding_v4._TOOLS_TEMPLATE = <Multiline-String>#
bridge.models.deepseek.data.encoding_v4._to_json(value: Any) str#
bridge.models.deepseek.data.encoding_v4._openai_tools(
tools: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
) list[collections.abc.Mapping[str, Any]]#
bridge.models.deepseek.data.encoding_v4._openai_tool_calls(
tool_calls: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
) list[dict[str, Any]]#
bridge.models.deepseek.data.encoding_v4._encode_arguments_to_dsml(
tool_call: collections.abc.Mapping[str, Any],
) str#
bridge.models.deepseek.data.encoding_v4._render_tools(
tools: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
) str#
bridge.models.deepseek.data.encoding_v4._last_user_index(
messages: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
) int#
bridge.models.deepseek.data.encoding_v4._render_message(
index: int,
messages: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
*,
thinking_mode: Literal[chat, thinking],
truncate_history_thinking: bool,
reasoning_effort: Literal[high, max] | None,
) str#
bridge.models.deepseek.data.encoding_v4._merge_tool_messages(
messages: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
) list[dict[str, Any]]#
bridge.models.deepseek.data.encoding_v4._sort_tool_results(
messages: list[dict[str, Any]],
) list[dict[str, Any]]#
bridge.models.deepseek.data.encoding_v4._drop_historical_thinking(
messages: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
) list[dict[str, Any]]#
bridge.models.deepseek.data.encoding_v4.encode_deepseek_v4_messages(
messages: collections.abc.Sequence[collections.abc.Mapping[str, Any]],
*,
thinking_mode: Literal[chat, thinking],
truncate_history_thinking: bool = True,
reasoning_effort: Literal[high, max] | None = None,
add_bos: bool = True,
) str#

Encode OpenAI-style messages with the official DeepSeek-V4 contract.

Parameters:
  • messages – Structured chat turns. Tool definitions belong on a system or developer message; standalone tool results are merged automatically.

  • thinking_modechat emits </think> immediately after the assistant marker; thinking emits explicit reasoning spans.

  • truncate_history_thinking – Remove reasoning from historical assistant turns. The official contract disables this automatically when tools are present.

  • reasoning_effort – Optional high or max reasoning policy.

  • add_bos – Prepend the DeepSeek beginning-of-sequence token.

Returns:

Fully rendered DeepSeek-V4 conversation text ready for tokenization.