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§
Enums§
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.
imagescontains only records belonging to the current turn, matching the official helper’s context-cache contract. - encode_
messages_ simple - merge_
tool_ messages - Merge standalone OpenAI
toolmessages 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