vllm.renderers.chat_utils.chat_message
¶
Functions:
-
get_full_multimodal_text_prompt–Combine multimodal prompts for a multimodal language model.
-
has_non_text_content–Whether any message in
messageshas a non-text content part. -
parse_chat_message_content_mm_part–Parses a given multi-modal content part based on its type.
-
parse_chat_message_content_part–Parses a single part of a conversation. If wrap_dicts is True,
_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/renderers/chat_utils/chat_message.py
_strip_claude_code_billing_header(parts)
¶
Drop Claude Code's attribution header line from system text parts.
Its cch value changes on every request, so a prompt that keeps it
misses the prefix cache from the header on. Gateways that translate
Anthropic requests to chat completions keep it; /v1/messages drops
the same block.
Source code in vllm/renderers/chat_utils/chat_message.py
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/renderers/chat_utils/chat_message.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
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/renderers/chat_utils/chat_message.py
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 | |
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/renderers/chat_utils/chat_message.py
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 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 | |