deepseek-recipe README

The project's README from github.com/deepseek-ai/deepseek-recipe. As one markdown file: README.md.

DeepSeek

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, render conversations into prompts for DeepSeek models, encode conversations into token IDs with an attached tokenizer, 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. The caller must provide model inference, tool execution, and HTTP transport.

Getting started · Streaming response · Use with tokenizer · License

Supported scope

Using deepseek-recipe

The examples below convert a Chat Completions request into a DeepSeek V4.1 prompt. The library resolves the model version from the request's model name and accepts DeepSeek-V4-Pro and DeepSeek-V4.1-Flash by default; register other names, such as deepseek-flash, with ConversionOptions::with_model_alias.

Python

Installation

Python 3.10+:

python3 -m pip install deepseek-recipe

Example

from deepseek_recipe import ChatCompletionRequest, ConversionOptions, DeepseekV41Encoding

request = ChatCompletionRequest({
    "model": "DeepSeek-V4.1-Flash",
    "messages": [{"role": "user", "content": "Hello"}],
})
converted = request.convert(ConversionOptions())
rendered = DeepseekV41Encoding().render_conversation(converted.conversation)
print(rendered.prompt)

Rust

Installation

cargo add [email protected] [email protected] serde_json@1

See the development guide for source builds and image dependencies.

Example

use deepseek_recipe::openai::ChatCompletionRequest;
use deepseek_recipe::request::{ConversionOptions, ProtocolRequest};
use deepseek_recipe_encoding::PromptEncoding;
use deepseek_recipe_encoding::v4::dsv41::DeepseekV41Encoding;
use serde_json::json;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let request: ChatCompletionRequest = serde_json::from_value(json!({
        "model": "DeepSeek-V4.1-Flash",
        "messages": [{"role": "user", "content": "Hello"}],
    }))?;
    let converted = request.convert(ConversionOptions::default())?;
    let rendered = DeepseekV41Encoding::new().render_conversation(&converted.conversation);
    println!("{}", rendered.prompt);
    Ok(())
}

Encoding & Decoding Demo

Run the demo from the repository root to render prompts from requests and parse model output into protocol responses:

cargo run -p encoding-decoding-demo --locked

Open http://127.0.0.1:7778.

More examples

Rust and Python both support converting model output into streaming responses. See the Streaming response. 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-macros The prompt! macro used by prompt rendering.
deepseek-recipe-python Python bindings, imported as deepseek_recipe.
encoding-decoding-demo A web interface that renders prompts, highlights special tokens, and parses complete model output into Chat Completions, Responses, or Messages responses.
server-rs An Axum API example with mock inference.
server-py A FastAPI example with mock inference.

License

Project code and public documentation are licensed under the MIT License. Bundled tokenizer notices are in static/tokenizers/README.md.

deepseek-recipe (deepseek-ai/deepseek-recipe)

Searching Database…

What is this?deepseek-recipe is a set of Rust libraries (with Python bindings) that convert API requests in different formats into DeepSeek's internal Conversation format, render that into prompts, encode conversations into token IDs, and convert model output back into responses matching the original request format.
Is this a library or a full inference server?It is a library you embed in your own service. It only handles protocol conversion and prompt rendering; the caller still has to supply model inference, tool execution, and HTTP transport.
How do I add this to a project?Use the Python package (requires Python 3.10+) or add the Rust crates via Cargo; both let you convert a Chat Completions request into a DeepSeek V4 or V4.1 prompt. There's also an encoding-decoding-demo web UI to try prompt rendering and output parsing without writing code.
What do I need to bring myself to actually run inference?Your own inference backend, tool execution, and HTTP transport — this library only converts protocols and renders prompts, it doesn't run the model.
Does it support images for every DeepSeek model?No. Images are preprocessed with OpenCV for DeepSeek V4.1 only; DeepSeek V4 doesn't accept images at all, so conversion replaces each image with the text '[Unsupported Image]'.
What request formats can it convert between?It converts between Messages, Chat Completions, and Responses formats, covering both streaming and complete responses.
Does it support tool calling and structured output?Yes: function tools (plus Responses tool namespaces and the apply_patch custom tool), and structured output via JSON Schema or regex response formats that get validated and injected into the prompt.
Can it report token usage and log probabilities?If you attach a tokenizer, it can count reasoning tokens and surface Chat Completions/Responses log-probability fields, but it never computes probabilities itself — the backend must supply those values.
What are the individual packages for?deepseek-recipe-core holds shared types, deepseek-recipe-encoding does prompt rendering and token encoding, deepseek-recipe-image handles image fetching/preprocessing, and deepseek-recipe-python exposes the Python bindings; server-rs/server-py are example API servers with mock inference.
Size
2.2 MB
Stars
2.9K
Updated
CommitOct 19
Age
2mo
Commits · 90 Days