Skip to content

vllm.entrypoints.pooling.base.protocol

logger module-attribute

logger = init_logger(__name__)

ChatRequestMixin

Bases: OpenAIBaseModel

Source code in vllm/entrypoints/pooling/base/protocol.py
class ChatRequestMixin(OpenAIBaseModel):
    # --8<-- [start:chat-params]
    messages: list[ChatCompletionMessageParam]
    # --8<-- [end:chat-params]

    # --8<-- [start:chat-extra-params]
    add_generation_prompt: bool = Field(
        default=False,
        description=(
            "If true, the generation prompt will be added to the chat template. "
            "This is a parameter used by chat template in tokenizer config of the "
            "model."
        ),
    )
    continue_final_message: bool = Field(
        default=False,
        description=(
            "If this is set, the chat will be formatted so that the final "
            "message in the chat is open-ended, without any EOS tokens. The "
            "model will continue this message rather than starting a new one. "
            'This allows you to "prefill" part of the model\'s response for it. '
            "Cannot be used at the same time as `add_generation_prompt`."
        ),
    )
    add_special_tokens: bool = Field(
        default=False,
        description=(
            "If true, special tokens (e.g. BOS) will be added to the prompt "
            "on top of what is added by the chat template. "
            "For most models, the chat template takes care of adding the "
            "special tokens so this should be set to false (as is the "
            "default)."
        ),
    )
    chat_template: str | None = Field(
        default=None,
        description=(
            "A Jinja template to use for this conversion. "
            "As of transformers v4.44, default chat template is no longer "
            "allowed, so you must provide a chat template if the tokenizer "
            "does not define one."
        ),
    )
    chat_template_kwargs: dict[str, Any] | None = Field(
        default=None,
        description=(
            "Additional keyword args to pass to the template renderer. "
            "Will be accessible by the chat template."
        ),
    )
    # --8<-- [end:chat-extra-params]

    @model_validator(mode="before")
    @classmethod
    def check_generation_prompt(cls, data):
        if data.get("continue_final_message") and data.get("add_generation_prompt"):
            raise ValueError(
                "Cannot set both `continue_final_message` and "
                "`add_generation_prompt` to True."
            )
        return data

    def build_chat_params(
        self,
        default_template: str | None,
        default_template_content_format: ChatTemplateContentFormatOption,
    ) -> ChatParams:
        return ChatParams(
            chat_template=self.chat_template or default_template,
            chat_template_content_format=default_template_content_format,
            chat_template_kwargs=merge_kwargs(
                self.chat_template_kwargs,
                dict(
                    add_generation_prompt=self.add_generation_prompt,
                    continue_final_message=self.continue_final_message,
                ),
            ),
        )

add_generation_prompt class-attribute instance-attribute

add_generation_prompt: bool = Field(
    default=False,
    description="If true, the generation prompt will be added to the chat template. This is a parameter used by chat template in tokenizer config of the model.",
)

add_special_tokens class-attribute instance-attribute

add_special_tokens: bool = Field(
    default=False,
    description="If true, special tokens (e.g. BOS) will be added to the prompt on top of what is added by the chat template. For most models, the chat template takes care of adding the special tokens so this should be set to false (as is the default).",
)

chat_template class-attribute instance-attribute

chat_template: str | None = Field(
    default=None,
    description="A Jinja template to use for this conversion. As of transformers v4.44, default chat template is no longer allowed, so you must provide a chat template if the tokenizer does not define one.",
)

chat_template_kwargs class-attribute instance-attribute

chat_template_kwargs: dict[str, Any] | None = Field(
    default=None,
    description="Additional keyword args to pass to the template renderer. Will be accessible by the chat template.",
)

continue_final_message class-attribute instance-attribute

continue_final_message: bool = Field(
    default=False,
    description='If this is set, the chat will be formatted so that the final message in the chat is open-ended, without any EOS tokens. The model will continue this message rather than starting a new one. This allows you to "prefill" part of the model\'s response for it. Cannot be used at the same time as `add_generation_prompt`.',
)

messages instance-attribute

build_chat_params

build_chat_params(
    default_template: str | None,
    default_template_content_format: ChatTemplateContentFormatOption,
) -> ChatParams
Source code in vllm/entrypoints/pooling/base/protocol.py
def build_chat_params(
    self,
    default_template: str | None,
    default_template_content_format: ChatTemplateContentFormatOption,
) -> ChatParams:
    return ChatParams(
        chat_template=self.chat_template or default_template,
        chat_template_content_format=default_template_content_format,
        chat_template_kwargs=merge_kwargs(
            self.chat_template_kwargs,
            dict(
                add_generation_prompt=self.add_generation_prompt,
                continue_final_message=self.continue_final_message,
            ),
        ),
    )

check_generation_prompt classmethod

check_generation_prompt(data)
Source code in vllm/entrypoints/pooling/base/protocol.py
@model_validator(mode="before")
@classmethod
def check_generation_prompt(cls, data):
    if data.get("continue_final_message") and data.get("add_generation_prompt"):
        raise ValueError(
            "Cannot set both `continue_final_message` and "
            "`add_generation_prompt` to True."
        )
    return data

ClassifyRequestMixin

Bases: OpenAIBaseModel

Source code in vllm/entrypoints/pooling/base/protocol.py
class ClassifyRequestMixin(OpenAIBaseModel):
    # --8<-- [start:classify-extra-params]
    use_activation: bool | None = Field(
        default=None,
        description="Whether to use activation for the pooler outputs. "
        "`None` uses the pooler's default, which is `True` in most cases.",
    )
    # --8<-- [end:classify-extra-params]

    def to_pooling_params(self):
        return PoolingParams(
            use_activation=self.use_activation,
            truncate_prompt_tokens=getattr(self, "truncate_prompt_tokens", None),
        )

use_activation class-attribute instance-attribute

use_activation: bool | None = Field(
    default=None,
    description="Whether to use activation for the pooler outputs. `None` uses the pooler's default, which is `True` in most cases.",
)

to_pooling_params

to_pooling_params()
Source code in vllm/entrypoints/pooling/base/protocol.py
def to_pooling_params(self):
    return PoolingParams(
        use_activation=self.use_activation,
        truncate_prompt_tokens=getattr(self, "truncate_prompt_tokens", None),
    )

CompletionRequestMixin

Bases: OpenAIBaseModel

Source code in vllm/entrypoints/pooling/base/protocol.py
class CompletionRequestMixin(OpenAIBaseModel):
    # --8<-- [start:completion-params]
    input: list[int] | list[list[int]] | str | list[str]
    # --8<-- [end:completion-params]

    # --8<-- [start:completion-extra-params]
    add_special_tokens: bool = Field(
        default=True,
        description=(
            "If true (the default), special tokens (e.g. BOS) will be added to "
            "the prompt."
        ),
    )

add_special_tokens class-attribute instance-attribute

add_special_tokens: bool = Field(
    default=True,
    description="If true (the default), special tokens (e.g. BOS) will be added to the prompt.",
)

input instance-attribute

input: list[int] | list[list[int]] | str | list[str]

EmbedRequestMixin

Bases: EncodingRequestMixin

Source code in vllm/entrypoints/pooling/base/protocol.py
class EmbedRequestMixin(EncodingRequestMixin):
    # --8<-- [start:embed-params]
    dimensions: int | None = None
    # --8<-- [end:embed-params]

    # --8<-- [start:embed-extra-params]
    use_activation: bool | None = Field(
        default=None,
        description="Whether to use activation for the pooler outputs. "
        "`None` uses the pooler's default, which is `True` in most cases.",
    )
    normalize: bool | None = Field(
        default=None,
        description="Deprecated; please pass `use_activation` instead",
    )
    # --8<-- [end:embed-extra-params]

    def to_pooling_params(self):
        if self.normalize is not None:
            logger.warning_once(
                "`normalize` is deprecated and will be removed in v0.17. "
                "Please pass `use_activation` instead."
            )
            self.use_activation = self.normalize

        return PoolingParams(
            dimensions=self.dimensions,
            use_activation=self.use_activation,
            truncate_prompt_tokens=getattr(self, "truncate_prompt_tokens", None),
        )

dimensions class-attribute instance-attribute

dimensions: int | None = None

normalize class-attribute instance-attribute

normalize: bool | None = Field(
    default=None,
    description="Deprecated; please pass `use_activation` instead",
)

use_activation class-attribute instance-attribute

use_activation: bool | None = Field(
    default=None,
    description="Whether to use activation for the pooler outputs. `None` uses the pooler's default, which is `True` in most cases.",
)

to_pooling_params

to_pooling_params()
Source code in vllm/entrypoints/pooling/base/protocol.py
def to_pooling_params(self):
    if self.normalize is not None:
        logger.warning_once(
            "`normalize` is deprecated and will be removed in v0.17. "
            "Please pass `use_activation` instead."
        )
        self.use_activation = self.normalize

    return PoolingParams(
        dimensions=self.dimensions,
        use_activation=self.use_activation,
        truncate_prompt_tokens=getattr(self, "truncate_prompt_tokens", None),
    )

EncodingRequestMixin

Bases: OpenAIBaseModel

Source code in vllm/entrypoints/pooling/base/protocol.py
class EncodingRequestMixin(OpenAIBaseModel):
    # --8<-- [start:encoding-params]
    encoding_format: EncodingFormat = "float"
    # --8<-- [end:encoding-params]

    # --8<-- [start:encoding-extra-params]
    embed_dtype: EmbedDType = Field(
        default="float32",
        description=(
            "What dtype to use for encoding. Default to using float32 for base64 "
            "encoding to match the OpenAI python client behavior. "
            "This parameter will affect base64 and binary_response."
        ),
    )
    endianness: Endianness = Field(
        default="native",
        description=(
            "What endianness to use for encoding. Default to using native for "
            "base64 encoding to match the OpenAI python client behavior."
            "This parameter will affect base64 and binary_response."
        ),
    )

embed_dtype class-attribute instance-attribute

embed_dtype: EmbedDType = Field(
    default="float32",
    description="What dtype to use for encoding. Default to using float32 for base64 encoding to match the OpenAI python client behavior. This parameter will affect base64 and binary_response.",
)

encoding_format class-attribute instance-attribute

encoding_format: EncodingFormat = 'float'

endianness class-attribute instance-attribute

endianness: Endianness = Field(
    default="native",
    description="What endianness to use for encoding. Default to using native for base64 encoding to match the OpenAI python client behavior.This parameter will affect base64 and binary_response.",
)

PoolingBasicRequestMixin

Bases: OpenAIBaseModel

Source code in vllm/entrypoints/pooling/base/protocol.py
class PoolingBasicRequestMixin(OpenAIBaseModel):
    # --8<-- [start:pooling-common-params]
    model: str | None = None
    user: str | None = None
    # --8<-- [end:pooling-common-params]

    # --8<-- [start:pooling-common-extra-params]
    truncate_prompt_tokens: Annotated[int, Field(ge=-1)] | None = None
    request_id: str = Field(
        default_factory=random_uuid,
        description=(
            "The request_id related to this request. If the caller does "
            "not set it, a random_uuid will be generated. This id is used "
            "through out the inference process and return in response."
        ),
    )
    priority: int = Field(
        default=0,
        description=(
            "The priority of the request (lower means earlier handling; "
            "default: 0). Any priority other than 0 will raise an error "
            "if the served model does not use priority scheduling."
        ),
    )

model class-attribute instance-attribute

model: str | None = None

priority class-attribute instance-attribute

priority: int = Field(
    default=0,
    description="The priority of the request (lower means earlier handling; default: 0). Any priority other than 0 will raise an error if the served model does not use priority scheduling.",
)

request_id class-attribute instance-attribute

request_id: str = Field(
    default_factory=random_uuid,
    description="The request_id related to this request. If the caller does not set it, a random_uuid will be generated. This id is used through out the inference process and return in response.",
)

truncate_prompt_tokens class-attribute instance-attribute

truncate_prompt_tokens: (
    Annotated[int, Field(ge=-1)] | None
) = None

user class-attribute instance-attribute

user: str | None = None