Skip to content

prompt_embeds_parts

The prompt_embeds chat content part, extended to carry a content identifier hash.

vLLM's part carries base64 tensor bytes and nothing else:

{"type": "prompt_embeds", "data": "<base64>"}

Protopia Output Protection additionally accepts an id, so a client that has uploaded embeddings once can reference them on later turns instead of re-sending them:

This module only reads and classifies parts. Resolving an identifier, answering a miss and rewriting a part for vLLM all belong to the caller.

Classes:

Name Description
MalformedPromptEmbedsPartError

Raised when a content part claims to carry prompt embeddings but cannot be acted on.

PromptEmbedsPart

One prompt_embeds content part, located within a request body and classified.

Functions:

Name Description
iter_prompt_embeds_parts

Find and classify every prompt_embeds content part in a chat completion request body.

Attributes:

Name Type Description
PROMPT_EMBEDS_PART_TYPE Final[str]

Value of a content part's type that marks it as carrying prompt embeddings.

PROMPT_EMBEDS_PART_TYPE module-attribute

PROMPT_EMBEDS_PART_TYPE: Final[str] = 'prompt_embeds'

Value of a content part's type that marks it as carrying prompt embeddings.

MalformedPromptEmbedsPartError

Bases: ValueError

Raised when a content part claims to carry prompt embeddings but cannot be acted on.

PromptEmbedsPart dataclass

One prompt_embeds content part, located within a request body and classified.

Attributes:

Name Type Description
has_data bool

Whether the part carries base64 tensor bytes of its own.

identifier str | None

The content identifier the part references, or None for a plain vLLM part.

needs_resolving bool

Whether this part references embeddings it does not carry, and so has to be looked up.

part dict[str, object]

The part itself, so a caller holding this can rewrite it in place.

has_data instance-attribute

has_data: bool

Whether the part carries base64 tensor bytes of its own.

identifier instance-attribute

identifier: str | None

The content identifier the part references, or None for a plain vLLM part.

needs_resolving property

needs_resolving: bool

Whether this part references embeddings it does not carry, and so has to be looked up.

part instance-attribute

part: dict[str, object]

The part itself, so a caller holding this can rewrite it in place.

iter_prompt_embeds_parts

iter_prompt_embeds_parts(
    body: object,
) -> list[PromptEmbedsPart]

Find and classify every prompt_embeds content part in a chat completion request body.

Anything that is not shaped like a chat request is ignored rather than rejected, this runs ahead of vLLM's own validation.

Parameters:

Name Type Description Default

body

object

The decoded JSON request body.

required

Returns:

Type Description
list[PromptEmbedsPart]

Every prompt_embeds part found, in the order the request lists them.

Raises:

Type Description
MalformedPromptEmbedsPartError

If any such part cannot be acted on.