[Bugfix][Frontend] Guard remaining before-validators against non-object JSON bodies (#52528)
Signed-off-by: Kaif <kaifkohari10@gmail.com>
This commit is contained in:
@@ -413,6 +413,8 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_response_format(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
response_format = data.get("response_format")
|
||||
if response_format is None:
|
||||
return data
|
||||
@@ -444,6 +446,8 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def check_structured_outputs_count(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if data.get("structured_outputs", None) is None:
|
||||
return data
|
||||
|
||||
@@ -472,6 +476,8 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def check_logprobs(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if data.get("logprob_token_ids") and data.get("use_beam_search"):
|
||||
raise VLLMValidationError(
|
||||
"`logprob_token_ids` is not supported with beam search.",
|
||||
@@ -532,6 +538,8 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_stream_options(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if data.get("stream_options") and not data.get("stream"):
|
||||
raise VLLMValidationError(
|
||||
"Stream options can only be defined when `stream=True`.",
|
||||
@@ -543,6 +551,8 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_prompt_and_prompt_embeds(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
prompt = data.get("prompt")
|
||||
prompt_embeds = data.get("prompt_embeds")
|
||||
|
||||
@@ -562,6 +572,8 @@ class CompletionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_prompt_list_length(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
max_prompts = envs.VLLM_MAX_COMPLETION_PROMPTS
|
||||
|
||||
prompt = data.get("prompt")
|
||||
|
||||
@@ -467,6 +467,8 @@ class ResponsesRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_background(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if not data.get("background"):
|
||||
return data
|
||||
if not data.get("store", True):
|
||||
@@ -479,6 +481,8 @@ class ResponsesRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_prompt(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if data.get("prompt") is not None:
|
||||
raise VLLMValidationError(
|
||||
"prompt template is not supported", parameter="prompt"
|
||||
@@ -499,6 +503,8 @@ class ResponsesRequest(OpenAIBaseModel):
|
||||
|
||||
Invalid structures are left for Pydantic to reject.
|
||||
"""
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
input_data = data.get("input")
|
||||
|
||||
# Early return for None, strings, or bytes
|
||||
|
||||
@@ -239,6 +239,8 @@ class ChatRequestOptionsMixin(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def check_generation_prompt(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if data.get("continue_final_message") and data.get("add_generation_prompt"):
|
||||
raise VLLMValidationError(
|
||||
"Cannot set both `continue_final_message` and "
|
||||
|
||||
@@ -120,6 +120,8 @@ class TokenizeChatRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def check_generation_prompt(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if data.get("continue_final_message") and data.get("add_generation_prompt"):
|
||||
raise VLLMValidationError(
|
||||
"Cannot set both `continue_final_message` and "
|
||||
|
||||
@@ -285,6 +285,8 @@ class TranscriptionRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_transcription_request(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
if isinstance(data.get("file"), str):
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.UNPROCESSABLE_ENTITY,
|
||||
|
||||
@@ -271,6 +271,8 @@ class TranslationRequest(OpenAIBaseModel):
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_stream_options(cls, data):
|
||||
if not isinstance(data, dict):
|
||||
return data
|
||||
stream_opts = ["stream_include_usage", "stream_continuous_usage_stats"]
|
||||
stream = data.get("stream", False)
|
||||
if any(bool(data.get(so, False)) for so in stream_opts) and not stream:
|
||||
|
||||
Reference in New Issue
Block a user