deepseek-recipe
English | 中文
deepseek-recipe is a collection of Rust libraries and Python bindings that uniformly convert API requests in different formats into the Conversation format, encode them into prompts for DeepSeek models, and convert model output into responses in the corresponding format. Use these components to connect an inference backend to API services that support multiple formats. Model inference, tool execution, and HTTP transport must be provided externally.
Getting started · Streaming · Use with tokenizer · Contributing · License
Supported scope
- Request/response formats: Conversion of Messages, Chat Completions, and Responses requests, streamed responses, and complete responses. Supports text, images, thinking, and client tool calls.
- Prompts: Encoding of DeepSeek V4 and V4.1 conversations into prompts or token IDs.
- Generation settings: Thinking mode, reasoning effort,
temperature,top_p, and output token limits. - Output parsing: Thinking, tool calls, JSON object output, and stop sequences.
- Images: Provided as base64 or external URLs. The image component provides DeepSeek V4.1 preprocessing with OpenCV.
- Tool definitions: Function tools; the Responses API also supports tool
namespaces and the
apply_patchcustom tool.
Not yet supported
- Token probabilities (
logprobsandtop_logprobs). - Document content, audio/video input, and file retrieval by
file_id. - Server tool execution, such as
web_search. - JSON Schema and regex output constraints, or enforcement of tool
strictsettings. - Multiple completions per Chat Completions request (
n > 1). - Responses custom tool definitions other than
apply_patch. - Responses conversation storage and context retrieval through
previous_response_id. - Responses encrypted thinking content (
encrypted_content).
Using deepseek-recipe
To convert a Chat Completions request into a DeepSeek V4.1 prompt:
Python
Installation
Python 3.10+:
Example
=
=
=
Rust
Installation
See the development guide for source builds and image dependencies.
Example
use ChatCompletionRequest;
use ;
use PromptEncoding;
use DeepseekV41Encoding;
use json;
Encoding & Decoding Demo
Run the encoding and decoding demo from the repository root:
Open http://127.0.0.1:7778.
More examples
Rust and Python both support converting model output into streaming responses. See the streaming examples. To encode conversations into token IDs or decode backend token IDs, see use with tokenizer.
Packages and example projects
| Package | Purpose |
|---|---|
deepseek-recipe |
Protocol conversion and model output parsing. |
deepseek-recipe-core |
Shared conversation, message, image, and tool types. |
deepseek-recipe-encoding |
DeepSeek V4 and V4.1 prompt rendering and token encoding. |
deepseek-recipe-image |
Image fetching and preprocessing. |
deepseek-recipe-python |
Python bindings, imported as deepseek_recipe. |
| encoding-decoding-demo | A web interface for encoding prompts, inspecting special tokens, and decoding complete model output into Chat Completions, Responses, or Messages. |
| server-rs | An Axum API example with mock inference. |
| server-py | A FastAPI example with mock inference or a gRPC backend. |
License
Project code and public documentation are licensed under the MIT License. Bundled tokenizer notices are in static/tokenizers/README.md.