vllm.tokenizers.deepseek_v41_encoding ¶
Text encoding adapted from the DeepSeek V4.1 reference encoder.
Message normalization and serving controls live in deepseek_v41.py.
Functions:
-
encode_arguments_to_dsml–Encode tool call arguments into V4.1 DSML parameter format.
-
encode_messages–Encode preprocessed (text-only) messages into the V4.1 prompt format.
-
find_last_user_index–Find the index of the last user/developer message.
-
merge_tool_messages–Merge tool messages into the preceding user message using content_blocks format.
-
render_message–Render a single message at the given index into its V4.1 encoded string form.
-
render_reasoning_effort–Render the V4.1 numeric reasoning effort prefix (thinking mode, index 0 only).
-
render_tools–Render tool schemas into the V4.1 system prompt format.
-
sort_tool_results_by_call_order–Sort tool_result blocks within user messages by the order of tool_calls
-
to_json–Serialize a value to JSON string.
-
tool_calls_from_openai_format–Convert OpenAI-format tool calls to internal format.
-
tools_from_openai_format–Extract function definitions from OpenAI-format tool list.
_drop_thinking_messages(messages) ¶
Drop reasoning_content and non-essential messages before the last user message. Same as V4, but uses the V4.1 last-user definition (mid systems count).
Source code in vllm/tokenizers/deepseek_v41_encoding.py
encode_arguments_to_dsml(tool_call) ¶
Encode tool call arguments into V4.1 DSML parameter format.
Source code in vllm/tokenizers/deepseek_v41_encoding.py
encode_messages(messages, thinking_mode, context=None, drop_thinking=True, add_default_bos_token=True, reasoning_effort=None) ¶
Encode preprocessed (text-only) messages into the V4.1 prompt format.
Source code in vllm/tokenizers/deepseek_v41_encoding.py
find_last_user_index(messages) ¶
Find the index of the last user/developer message.
V4.1 supports mid-conversation system messages, which count as user messages for the purposes of the assistant generation header.
Source code in vllm/tokenizers/deepseek_v41_encoding.py
merge_tool_messages(messages) ¶
Merge tool messages into the preceding user message using content_blocks format.
DeepSeek-V4.1 does not have a standalone "tool" role; instead, tool results are encoded as
Source code in vllm/tokenizers/deepseek_v41_encoding.py
render_message(index, messages, thinking_mode, drop_thinking=True, reasoning_effort=None) ¶
Render a single message at the given index into its V4.1 encoded string form.
Source code in vllm/tokenizers/deepseek_v41_encoding.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
render_reasoning_effort(index, thinking_mode, effort) ¶
Render the V4.1 numeric reasoning effort prefix (thinking mode, index 0 only).
Source code in vllm/tokenizers/deepseek_v41_encoding.py
render_tools(tools) ¶
Render tool schemas into the V4.1 system prompt format.
Source code in vllm/tokenizers/deepseek_v41_encoding.py
sort_tool_results_by_call_order(messages) ¶
Sort tool_result blocks within user messages by the order of tool_calls in the preceding assistant message.
Source code in vllm/tokenizers/deepseek_v41_encoding.py
to_json(value) ¶
tool_calls_from_openai_format(tool_calls) ¶
Convert OpenAI-format tool calls to internal format.