Skip to main content

Module dsv41_encoding

Module dsv41_encoding 

Source
Expand description

DeepSeek-V4.1 prompt encoding and completion parsing.

The V4.1 checkpoint intentionally ships without a Jinja chat template. This module is a Rust port of the official encoding/encoding.py at the pinned model revision. It keeps the protocol in one place for the CLI, OpenAI server, and any embedding application: spaced DSML tags, numeric reasoning effort, mid conversation system turns, tool result merging, and image ordering all follow the reference implementation.

Structs§

EncodeOptions
EncodedPrompt

Enums§

EncodingError
ReasoningEffort
ThinkingMode

Constants§

ASSISTANT_SP_TOKEN
BOS_TOKEN
DSML_TOKEN
EOS_TOKEN
IMAGE_PLACEHOLDER
LATEST_REMINDER_SP_TOKEN
SYSTEM_SP_TOKEN
TASK_TOKENS
Internal quick instruction tasks supported by the official formatter.
THINKING_END_TOKEN
THINKING_START_TOKEN
USER_SP_TOKEN

Functions§

encode_case
encode_messages
Encode current messages. images contains only records belonging to the current turn, matching the official helper’s context-cache contract.
encode_messages_simple
merge_tool_messages
Merge standalone OpenAI tool messages into a preceding user content list.
parse_message_from_completion_text
Parse a generated V4.1 completion into an OpenAI style assistant object.
parse_tagged_text
Convert compact <image>path</image> input to OpenAI style content blocks.
parse_tool_calls
process_image_messages
Normalize image blocks and return image records in prompt order.
render_message
Render one message exactly as the official Python implementation does.
sort_tool_results_by_call_order
Stable tool result order follows the preceding assistant’s tool call order.
to_json