vllm.entrypoints.openai.chat_completion.serving
¶
Classes:
OpenAIServingChat
¶
Bases: GenerateBaseServing
Methods:
-
chat_completion_stream_generator_raw–Yield chat chunks or errors without serializing them into SSE frames.
-
create_chat_completion–Chat Completion API similar to OpenAI's API.
-
render_chat_request–Validate the model and preprocess a chat completion request.
_create_chat_logprobs(token_ids, top_logprobs, tokenizer, num_output_top_logprobs=None, logprob_token_ids=None, return_as_token_id=None)
¶
Create OpenAI-style logprobs.
_create_chat_message(*args, **kwargs)
¶
Construct the response ChatMessage for the non-streaming path.
Subclasses can swap in a specialized ChatMessage subclass
(e.g. CohereServingChatV2 returning CohereChatMessage)
without duplicating the field selection in
assemble_chat_message_fields. The default returns a plain
ChatMessage.
_engine_chat_template_kwargs(chat_template_kwargs)
¶
Subclass hook to narrow chat_template_kwargs for the engine.
The same dict is used twice: to build the API-server-side parser
instance, and to populate
EngineCoreRequest.reasoning_parser_kwargs for the engine-core
side. The latter crosses ZMQ as msgpack, so a handler that stashes
request-scoped state only the API-server-side parser needs (values
msgpack can't encode, or payloads not worth shipping) can drop
those entries here without affecting the in-process parser.
Must not mutate the argument -- the caller still needs the full dict. The default forwards it unchanged.
_engine_reasoning_kwargs(request, parser, chat_template_kwargs, prompt_token_ids)
¶
reasoning_ended and reasoning_parser_kwargs for generate().
_finalize_response_message(message, *, parser)
¶
Subclass hook to enrich a fully-constructed ChatMessage.
Default is a no-op. Subclasses that need to surface parser-side
extras (e.g. CohereServingChatV2 reading grounding
citations off the reasoning parser and populating
CohereChatMessage.citations) override this to inspect
parser and mutate/replace message.
chat_completion_stream_generator_raw(request, result_generator, request_id, model_name, conversation, tokenizer, request_metadata, chat_template_kwargs=None, mm_token_counts=None)
async
¶
Yield chat chunks or errors without serializing them into SSE frames.
create_chat_completion(request, raw_request=None)
async
¶
Chat Completion API similar to OpenAI's API.
See https://platform.openai.com/docs/api-reference/chat/create for the API specification. This API mimics the OpenAI Chat Completion API.
render_chat_request(request, tok_params=None)
async
¶
Validate the model and preprocess a chat completion request.
Delegates preprocessing logic to OnlineRenderer, adding the engine-aware checks (LoRA model validation, engine health).
Returns:
-
tuple[list[ConversationMessage], list[EngineInput]] | ErrorResponse–A tuple of (conversation, engine_inputs) on success,
-
tuple[list[ConversationMessage], list[EngineInput]] | ErrorResponse–or an ErrorResponse on failure.
_get_mm_token_counts(engine_input)
¶
Sum per-modality placeholder tokens from mm_placeholders.
Keyed by modality name; PlaceholderRange.length is the placeholder's
prompt token span, so each sum matches the placeholder tokens already
counted in usage.prompt_tokens.
_make_prompt_tokens_details(enable_prompt_tokens_details, num_cached_tokens, num_cache_creation_tokens, mm_token_counts)
¶
Build prompt_tokens_details from cached + multimodal token counts.