vllm.renderers.chat_utils
¶
Modules:
-
chat_message– -
chat_template– -
content_parser– -
item_tracker– -
tool_call– -
types–
Classes:
-
BaseMultiModalItemTracker–Tracks multi-modal items in a given request and ensures that the number
-
ChatCompletionContentPartAudioEmbedsParam– -
ChatCompletionContentPartAudioParam– -
ChatCompletionContentPartImageEmbedsParam– -
ChatCompletionContentPartPromptEmbedsParam– -
ChatCompletionContentPartVideoEmbedsParam– -
ChatCompletionContentPartVideoParam– -
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.
-
PILImage–A PIL.Image.Image object.
Functions:
-
get_tool_call_id_type–Return the tool-call ID type for a given model configuration.
-
has_non_text_content–Whether any message in
messageshas a non-text content part. -
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.
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/renderers/chat_utils/item_tracker.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 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 | |
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/renderers/chat_utils/item_tracker.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/renderers/chat_utils/item_tracker.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/renderers/chat_utils/types.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
¶
Bases: TypedDict
Attributes:
Source code in vllm/renderers/chat_utils/types.py
type
instance-attribute
¶
The type of the content part.
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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.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
¶
Bases: TypedDict
Attributes:
Source code in vllm/renderers/chat_utils/types.py
type
instance-attribute
¶
The type of the content part.
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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.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/renderers/chat_utils/types.py
PILImage
¶
get_tool_call_id_type(model_config)
¶
Return the tool-call ID type for a given model configuration.
Source code in vllm/renderers/chat_utils/tool_call.py
has_non_text_content(messages)
¶
Whether any message in messages has a non-text content part.
Only list content is inspected, so validated chat content that is a one-shot iterator is never consumed.
Source code in vllm/renderers/chat_utils/chat_message.py
validate_chat_template(chat_template)
¶
Raises if the provided chat template appears invalid.