vllm.entrypoints.chat_utils ¶
Classes:
-
AsyncMultiModalContentParser– -
AudioURL– -
BaseMultiModalItemTracker–Tracks multi-modal items in a given request and ensures that the number
-
ChatCompletionContentPartAudioEmbedsParam– -
ChatCompletionContentPartAudioParam– -
ChatCompletionContentPartImageEmbedsParam– -
ChatCompletionContentPartPromptEmbedsParam– -
ChatCompletionContentPartVideoEmbedsParam– -
ChatCompletionContentPartVideoParam– -
ChatTemplateResolutionError–Raised when chat template resolution fails.
-
ConversationMessage– -
CustomChatCompletionContentPILImageParam–A simpler version of the param that only accepts a PIL image.
-
CustomChatCompletionContentSimpleAudioParam–A simpler version of the param that only accepts a plain audio_url.
-
CustomChatCompletionContentSimpleImageParam–A simpler version of the param that only accepts a plain image_url.
-
CustomChatCompletionContentSimpleVideoParam–A simpler version of the param that only accepts a plain audio_url.
-
CustomChatCompletionContentToolReferenceParam–A tool reference content param that only accepts a plain tool name.
-
CustomChatCompletionMessageParam–Enables custom roles in the Chat Completion API.
-
CustomThinkCompletionContentParam–A Think Completion Content Param that accepts a plain text and a boolean.
-
MultiModalContentParser– -
PILImage–A PIL.Image.Image object.
-
VideoURL–
Functions:
-
get_tool_call_id_type–Return the tool-call ID type for a given model configuration.
-
validate_chat_template–Raises if the provided chat template appears invalid.
Attributes:
-
PROMPT_EMBEDS_PLACEHOLDER_TOKEN(Final[str]) –The special token used as a placeholder for each embedding
PROMPT_EMBEDS_PLACEHOLDER_TOKEN = '<prompt_embeds>' module-attribute ¶
The special token used as a placeholder for each embedding position during chat template rendering.
Registered as an additional special token when --enable-prompt-embeds is set. See _ensure_prompt_embeds_placeholder_token in vllm/renderers/hf.py.
AsyncMultiModalContentParser ¶
Bases: BaseMultiModalContentParser
Methods:
-
parse_prompt_embeds–Schedule async prompt embeds decode and store the coroutine in the tracker.
Source code in vllm/entrypoints/chat_utils.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 | |
parse_prompt_embeds(data) ¶
Schedule async prompt embeds decode and store the coroutine in the tracker.
Like the sync variant, emits a single sentinel PROMPT_EMBEDS_PLACEHOLDER_TOKEN per content part. Unlike the sync variant, the tensor decode is deferred to a thread-pool executor via safe_load_prompt_embeds_async.
Source code in vllm/entrypoints/chat_utils.py
AudioURL ¶
BaseMultiModalItemTracker ¶
Tracks multi-modal items in a given request and ensures that the number of multi-modal items in a given request does not exceed the configured maximum per prompt.
Methods:
-
add–Add a multi-modal item to the current prompt and returns the
Attributes:
-
use_unified_vision_chunk_modality(bool) –Check if model uses unified vision_chunk modality for images/videos.
Source code in vllm/entrypoints/chat_utils.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 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 | |
use_unified_vision_chunk_modality cached property ¶
Check if model uses unified vision_chunk modality for images/videos.
_validate_add(modality) ¶
Validate that one more item of the modality can be tracked.
Source code in vllm/entrypoints/chat_utils.py
add(modality, item) ¶
Add a multi-modal item to the current prompt and returns the placeholder string to use, if any.
An optional uuid can be added which serves as a unique identifier of the media.
Note
prompt_embeds bypass MM-processor validation because they are pre-computed embeddings that do not go through any HF processor, encoder, or model-specific placeholder logic. The corresponding placeholder string is managed by the parser via _add_placeholder, so we return None here.
Source code in vllm/entrypoints/chat_utils.py
ChatCompletionContentPartAudioEmbedsParam ¶
Bases: TypedDict
Attributes:
-
audio_embeds(MultiModalEmbedsPayload | None) –The audio embeddings. It can be either:
-
type(Required[Literal['audio_embeds']]) –The type of the content part.
-
uuid(str | None) –User-provided UUID of a media. User must guarantee that it is properly
Source code in vllm/entrypoints/chat_utils.py
audio_embeds instance-attribute ¶
The audio embeddings. It can be either: - A single base64 string representing a serialized torch tensor. - A dictionary of base64 tensors or numeric JSON metadata arrays.
type instance-attribute ¶
The type of the content part.
uuid instance-attribute ¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
ChatCompletionContentPartAudioParam ¶
ChatCompletionContentPartImageEmbedsParam ¶
Bases: TypedDict
Attributes:
-
image_embeds(MultiModalEmbedsPayload | None) –The image embeddings. It can be either:
-
type(Required[Literal['image_embeds']]) –The type of the content part.
-
uuid(str | None) –User-provided UUID of a media. User must guarantee that it is properly
Source code in vllm/entrypoints/chat_utils.py
image_embeds instance-attribute ¶
The image embeddings. It can be either: - A single base64 string. - A dictionary of base64 tensors or numeric JSON metadata arrays.
type instance-attribute ¶
The type of the content part.
uuid instance-attribute ¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
ChatCompletionContentPartPromptEmbedsParam ¶
Bases: TypedDict
Attributes:
-
data(Required[str]) –Base64-encoded bytes of a serialized
torch.Tensorof shape -
type(Required[Literal['prompt_embeds']]) –The type of the content part.
Source code in vllm/entrypoints/chat_utils.py
ChatCompletionContentPartVideoEmbedsParam ¶
Bases: TypedDict
Attributes:
-
type(Required[Literal['video_embeds']]) –The type of the content part.
-
uuid(str | None) –User-provided UUID of a media. User must guarantee that it is properly
-
video_embeds(MultiModalEmbedsPayload | None) –The video embeddings. It can be either:
Source code in vllm/entrypoints/chat_utils.py
type instance-attribute ¶
The type of the content part.
uuid instance-attribute ¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
video_embeds instance-attribute ¶
The video embeddings. It can be either: - A single base64 string representing a serialized torch tensor. - A dictionary of base64 tensors or numeric JSON metadata arrays.
ChatCompletionContentPartVideoParam ¶
ChatTemplateResolutionError ¶
Bases: ValueError
Raised when chat template resolution fails.
This is a subclass of ValueError for backward compatibility with existing exception handlers.
ConversationMessage ¶
Bases: TypedDict
Attributes:
-
content(str | None | list[dict[str, str]]) –The contents of the message
-
name(str | None) –The name of the function to call
-
reasoning(str | None) –The reasoning content for interleaved thinking.
-
reasoning_content(str | None) –Deprecated: The reasoning content for interleaved thinking.
-
role(Required[str]) –The role of the message's author.
-
task(str | None) –Model-specific task marker. Currently passed through for DeepSeek V4.
-
tool_call_id(str | None) –Tool call that this message is responding to.
-
tool_calls(list[ChatCompletionMessageToolCallParam] | None) –The tool calls generated by the model, such as function calls.
-
tools(list[ChatCompletionFunctionToolParam] | None) –The tools for developer role.
Source code in vllm/entrypoints/chat_utils.py
content instance-attribute ¶
The contents of the message
name instance-attribute ¶
The name of the function to call
reasoning instance-attribute ¶
The reasoning content for interleaved thinking.
reasoning_content instance-attribute ¶
Deprecated: The reasoning content for interleaved thinking.
role instance-attribute ¶
The role of the message's author.
task instance-attribute ¶
Model-specific task marker. Currently passed through for DeepSeek V4.
tool_call_id instance-attribute ¶
Tool call that this message is responding to.
tool_calls instance-attribute ¶
The tool calls generated by the model, such as function calls.
tools instance-attribute ¶
The tools for developer role.
CustomChatCompletionContentPILImageParam ¶
Bases: TypedDict
A simpler version of the param that only accepts a PIL image.
Example: { "image_pil": ImageAsset('cherry_blossom').pil_image }
Attributes:
Source code in vllm/entrypoints/chat_utils.py
uuid instance-attribute ¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
CustomChatCompletionContentSimpleAudioParam ¶
Bases: TypedDict
A simpler version of the param that only accepts a plain audio_url.
Example: { "audio_url": "https://example.com/audio.mp3" }
Source code in vllm/entrypoints/chat_utils.py
CustomChatCompletionContentSimpleImageParam ¶
Bases: TypedDict
A simpler version of the param that only accepts a plain image_url. This is supported by OpenAI API, although it is not documented.
Example: { "image_url": "https://example.com/image.jpg" }
Attributes:
Source code in vllm/entrypoints/chat_utils.py
uuid instance-attribute ¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
CustomChatCompletionContentSimpleVideoParam ¶
Bases: TypedDict
A simpler version of the param that only accepts a plain audio_url.
Example: { "video_url": "https://example.com/video.mp4" }
Attributes:
Source code in vllm/entrypoints/chat_utils.py
uuid instance-attribute ¶
User-provided UUID of a media. User must guarantee that it is properly generated and unique for different medias.
CustomChatCompletionContentToolReferenceParam ¶
Bases: TypedDict
A tool reference content param that only accepts a plain tool name.
Example: { "name": "get_weather", "type": "tool_reference" }
Attributes:
-
name(str) –The name of the tool being referenced.
-
type(Literal['tool_reference']) –The content type.
Source code in vllm/entrypoints/chat_utils.py
CustomChatCompletionMessageParam ¶
Bases: TypedDict
Enables custom roles in the Chat Completion API.
Attributes:
-
content(str | list[ChatCompletionContentPartParam]) –The contents of the message.
-
name(str) –An optional name for the participant.
-
reasoning(str | None) –The reasoning content for interleaved thinking.
-
role(Required[str]) –The role of the message's author.
-
task(str | None) –Model-specific task marker. Currently passed through for DeepSeek V4.
-
tool_call_id(str | None) –Tool call that this message is responding to.
-
tool_calls(list[ChatCompletionMessageToolCallParam] | None) –The tool calls generated by the model, such as function calls.
-
tools(list[ChatCompletionFunctionToolParam] | None) –The tools for developer role.
Source code in vllm/entrypoints/chat_utils.py
content instance-attribute ¶
The contents of the message.
name instance-attribute ¶
An optional name for the participant.
Provides the model information to differentiate between participants of the same role.
reasoning instance-attribute ¶
The reasoning content for interleaved thinking.
role instance-attribute ¶
The role of the message's author.
task instance-attribute ¶
Model-specific task marker. Currently passed through for DeepSeek V4.
tool_call_id instance-attribute ¶
Tool call that this message is responding to.
tool_calls instance-attribute ¶
The tool calls generated by the model, such as function calls.
tools instance-attribute ¶
The tools for developer role.
CustomThinkCompletionContentParam ¶
Bases: TypedDict
A Think Completion Content Param that accepts a plain text and a boolean.
Example: { "thinking": "I am thinking about the answer", "closed": True, "type": "thinking" }
Attributes:
-
closed(bool) –Whether the thinking is closed.
-
thinking(Required[str]) –The thinking content.
-
type(Required[Literal['thinking']]) –The thinking type.
Source code in vllm/entrypoints/chat_utils.py
MultiModalContentParser ¶
Bases: BaseMultiModalContentParser
Methods:
-
parse_prompt_embeds–Decode a base64 prompt embeds tensor and store it in the tracker.
Source code in vllm/entrypoints/chat_utils.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 | |
parse_prompt_embeds(data) ¶
Decode a base64 prompt embeds tensor and store it in the tracker.
Emits a single PROMPT_EMBEDS_PLACEHOLDER_TOKEN sentinel per content part. The renderer later expands each sentinel to a span of tensor.shape[0] placeholder tokens after tokenization.
Source code in vllm/entrypoints/chat_utils.py
PILImage ¶
VideoURL ¶
_get_full_multimodal_text_prompt(placeholder_storage, texts, interleave_strings, multimodal_content_part_separator='\n') ¶
Combine multimodal prompts for a multimodal language model.
Source code in vllm/entrypoints/chat_utils.py
_parse_chat_message_content_mm_part(part) ¶
Parses a given multi-modal content part based on its type.
Parameters:
-
(part¶ChatCompletionContentPartParam) –A dict containing the content part, with a potential 'type' field.
Returns:
-
str–A tuple (part_type, content) where:
-
_ContentPart–- part_type: Type of the part (e.g., 'text', 'image_url').
-
tuple[str, _ContentPart]–- content: Parsed content (e.g., text, image URL).
Raises:
-
ValueError–If the 'type' field is missing and no direct URL is found.
Source code in vllm/entrypoints/chat_utils.py
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 | |
_parse_chat_message_content_part(part, mm_parser, *, wrap_dicts, interleave_strings) ¶
Parses a single part of a conversation. If wrap_dicts is True, structured dictionary pieces for texts and images will be wrapped in dictionaries, i.e., {"type": "text", "text", ...} and {"type": "image"}, respectively. Otherwise multimodal data will be handled by mm_parser, and texts will be returned as strings to be joined with multimodal placeholders.
Source code in vllm/entrypoints/chat_utils.py
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
_reject_reserved_placeholder_in_text(text, model_config) ¶
Reject user-supplied text parts that contains the reserved prompt_embeds placeholder sentinel.
When the server accepts prompt_embeds, the placeholder token is registered as a single unsplittable special token on the tokenizer. Any user text that happens to contain the literal sequence would tokenize to the same ID and be mistaken for a splice point by the renderer, letting a caller move or inject splice positions via plain text content.
Source code in vllm/entrypoints/chat_utils.py
_resolve_items(items_by_modality, mm_processor, modality_order) ¶
Materialize the tracker's per-modality items into mm_data / mm_uuids.
Note
mm_processor is None for text-only models (no registered HF processor) whose only modality is prompt_embeds. Every other modality requires a processor, enforced by the guard below.
Source code in vllm/entrypoints/chat_utils.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
get_tool_call_id_type(model_config) ¶
Return the tool-call ID type for a given model configuration.
Source code in vllm/entrypoints/chat_utils.py
validate_chat_template(chat_template) ¶
Raises if the provided chat template appears invalid.