Skip to content

vllm.renderers.chat_utils.chat_message

Functions:

_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.

_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.

get_full_multimodal_text_prompt(placeholder_storage, texts, interleave_strings, multimodal_content_part_separator='\n')

Combine multimodal prompts for a multimodal language model.

has_non_text_content(messages)

Whether any message has non-text content or reasoning.

Only list content is inspected, so validated chat content that is a one-shot iterator is never consumed.

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.

parse_chat_message_content_part(part, mm_parser, *, mm_tracker, 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.