vllm.parser.response_template
¶
Unified vLLM parser backed by checkpoint response_template metadata.
Classes:
-
ResponseTemplateParser–Parse reasoning, content, and tool calls with one response template.
-
ResponseTemplateReasoningParser–Reasoning end detection for a response-template parser.
-
ResponseTemplateToolParser–Selects a response-template parser as the tool parser;
Functions:
-
resolve_response_template–Return
templateif given, otherwise the tokenizer's metadata. -
response_template_parser_cls–The response-template parser that a registered reasoning or tool parser
-
validate_response_template_for_serving–Validate the template and reject semantic fields serving cannot route.
-
validate_tokenizer_response_template–Fail at startup if the tokenizer cannot serve the selected parsers,
ResponseTemplateParser
¶
Bases: Parser
Parse reasoning, content, and tool calls with one response template.
Methods:
-
count_reasoning_tokens–Count the generated tokens whose text the template parses as
Source code in vllm/parser/response_template.py
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
_constrain_request(request)
¶
Constrain request to the tool guarantees it asks for, or reject
those this parser cannot enforce.
Source code in vllm/parser/response_template.py
count_reasoning_tokens(token_ids)
¶
Count the generated tokens whose text the template parses as reasoning, continuing reasoning left open by the prompt.
Source code in vllm/parser/response_template.py
ResponseTemplateReasoningParser
¶
Bases: ReasoningParser
Reasoning end detection for a response-template parser.
ResponseTemplateParser parses the output; this parser tells it and the
structured-output engine where reasoning ends.
Methods:
-
unified_parser_cls–The unified parser that selecting this reasoning parser stands for.
Source code in vllm/parser/response_template.py
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 | |
unified_parser_cls()
classmethod
¶
The unified parser that selecting this reasoning parser stands for.
ResponseTemplateToolParser
¶
Bases: ToolParser
Selects a response-template parser as the tool parser;
ResponseTemplateParser extracts the tool calls.
Methods:
-
unified_parser_cls–The unified parser that selecting this tool parser stands for.
Source code in vllm/parser/response_template.py
unified_parser_cls()
classmethod
¶
_DeltaBuilder
¶
Accumulates one DeltaMessage.
Source code in vllm/parser/response_template.py
_ReasoningTokenCounter
¶
Counts the reasoning tokens of one growing generation, parsing each token once.
Source code in vllm/parser/response_template.py
_ResponseStream
¶
One generation fed through ResponseParser, routed to message deltas.
Source code in vllm/parser/response_template.py
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 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | |
_closer_rest()
¶
The rest of a closer the output stopped in after ending its region, when only the next message's start anchor is missing.
Source code in vllm/parser/response_template.py
_route_tool_event(event, delta)
¶
Emit the calls of a tool region once it ends and parses; a region cut off at the end of the stream is parsed as generated. With tool parsing disabled, the region passes through as content.
Source code in vllm/parser/response_template.py
_as_tool_dicts(tools)
¶
Responses function tools with flattened namespaces, plus chat tools.
Source code in vllm/parser/response_template.py
_ends_within(token_ids, end_ids, num_new)
¶
Whether end_ids completes within the last num_new of token_ids.
Source code in vllm/parser/response_template.py
_literal_ids(tokenizer, vocab, literals)
¶
Token ids of each literal, or None when one encodes to nothing.
Source code in vllm/parser/response_template.py
_reasoning_end_ids(tokenizer, vocab, template)
¶
Token ids of each thinking closer, or None when they are not all
literal.
Source code in vllm/parser/response_template.py
_serving_template(tokenizer, template)
¶
The validated streaming form of template or the tokenizer's metadata.
Source code in vllm/parser/response_template.py
_to_tool_calls(value)
¶
(name, arguments) of each call in a tool region value, or nothing if
any call is incomplete.
Source code in vllm/parser/response_template.py
_unsupported_tool_guarantee(request)
¶
The first requested tool guarantee this parser cannot enforce, with the request parameter that asked for it.
Source code in vllm/parser/response_template.py
resolve_response_template(tokenizer, template=None)
¶
Return template if given, otherwise the tokenizer's metadata.
Source code in vllm/parser/response_template.py
response_template_parser_cls(split_parser_cls)
¶
The response-template parser that a registered reasoning or tool parser
stands for, or None for any other parser.
Source code in vllm/parser/response_template.py
validate_response_template_for_serving(template)
¶
Validate the template and reject semantic fields serving cannot route.
Source code in vllm/parser/response_template.py
validate_tokenizer_response_template(tokenizer, *, reasoning_parser, tool_parser)
¶
Fail at startup if the tokenizer cannot serve the selected parsers, named as given on the command line.