Buckets:
| # DeepSeek-V4 text and vision encoding | |
| `encoding_dsv4.py` is the standalone prompt-format reference. It supports | |
| multi-turn conversations, tool calls, thinking modes, and interleaved image | |
| content blocks without importing the inference implementation. | |
| ## OpenAI-style messages | |
| ```python | |
| from encoding_dsv4 import encode_messages | |
| messages = [{ | |
| "role": "user", | |
| "content": [ | |
| {"type": "text", "text": "第一张图"}, | |
| { | |
| "type": "image_url", | |
| "image_url": {"url": "examples/images/carrots.jpeg"}, | |
| }, | |
| {"type": "text", "text": "有什么内容?"}, | |
| ], | |
| }] | |
| # non-thinking | |
| prompt, media = encode_messages( | |
| messages, | |
| thinking_mode="chat", | |
| return_multi_modal_data=True, | |
| ) | |
| # prompt: | |
| # '<|begin▁of▁sentence|><|User|>第一张图\n\n<|deepseek_image|>\n\n有什么内容?<|Assistant|></think>' | |
| # # thinking with `max` reasoning_effort | |
| # prompt, media = encode_messages( | |
| # messages, | |
| # thinking_mode="thinking", | |
| # reasoning_effort="max", | |
| # return_multi_modal_data=True, | |
| # ) | |
| # prompt: | |
| # <|begin▁of▁sentence|>Reasoning Effort: Beyond maximum — exhaustive, relentless, and uncompromising.\nYou MUST reason with the utmost depth and rigor, leaving absolutely nothing to chance: exhaustively decompose the problem into its most fundamental components, trace every causal chain to its root, and resolve the underlying cause rather than any surface symptom.\nDo not stop reasoning until you have independently verified the solution from multiple angles and are certain that no assumption remains unchecked and no error remains undiscovered.\n\n<|User|>第一张图\n\n<|deepseek_image|>\n\n有什么内容?<|Assistant|><think> | |
| ``` | |
| Images are represented in the prompt by `<|deepseek_image|>`. `media["images"]` | |
| contains the corresponding image records in exactly the same order. Pixel | |
| loading and expansion into model image tokens are handled by | |
| `inference/image_processor.py`. | |
| ## Compact TXT notation | |
| `parse_tagged_text()` converts a compact prompt such as | |
| ```text | |
| 第一张图<image>examples/images/carrots.jpeg</image>有什么内容? | |
| ``` | |
| into the same standard content blocks. It is an input convenience layer, not a | |
| second encoding implementation. | |
| ## Tests | |
| From the repository root: | |
| ```bash | |
| python -m pytest -q encoding/test_encoding_dsv4.py | |
| ``` | |
| The tests include a check that the TXT and JSON examples encode to the same | |
| prompt and preserve the same two-image ordering. | |
Xet Storage Details
- Size:
- 2.52 kB
- Xet hash:
- a8b80941a0f893228d6976239254fc0d40a0fae8c91fd666628c3f5131347ac5
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.