[Misc] Clean up ResponsesRequest model validators (#35531)
Signed-off-by: umut-polat <52835619+umut-polat@users.noreply.github.com>
This commit is contained in:
@@ -328,8 +328,9 @@ class ResponsesRequest(OpenAIBaseModel):
|
|||||||
# Also check text.format for OpenAI-style json_schema
|
# Also check text.format for OpenAI-style json_schema
|
||||||
if self.text is not None and self.text.format is not None:
|
if self.text is not None and self.text.format is not None:
|
||||||
if structured_outputs is not None:
|
if structured_outputs is not None:
|
||||||
raise ValueError(
|
raise VLLMValidationError(
|
||||||
"Cannot specify both structured_outputs and text.format"
|
"Cannot specify both structured_outputs and text.format",
|
||||||
|
parameter="structured_outputs",
|
||||||
)
|
)
|
||||||
response_format = self.text.format
|
response_format = self.text.format
|
||||||
if (
|
if (
|
||||||
@@ -378,14 +379,19 @@ class ResponsesRequest(OpenAIBaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@model_validator(mode="before")
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
def validate_background(cls, data):
|
def validate_background(cls, data):
|
||||||
if not data.get("background"):
|
if not data.get("background"):
|
||||||
return data
|
return data
|
||||||
if not data.get("store", True):
|
if not data.get("store", True):
|
||||||
raise ValueError("background can only be used when `store` is true")
|
raise VLLMValidationError(
|
||||||
|
"background can only be used when `store` is true",
|
||||||
|
parameter="background",
|
||||||
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@model_validator(mode="before")
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
def validate_prompt(cls, data):
|
def validate_prompt(cls, data):
|
||||||
if data.get("prompt") is not None:
|
if data.get("prompt") is not None:
|
||||||
raise VLLMValidationError(
|
raise VLLMValidationError(
|
||||||
@@ -394,16 +400,19 @@ class ResponsesRequest(OpenAIBaseModel):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@model_validator(mode="before")
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
def check_cache_salt_support(cls, data):
|
def check_cache_salt_support(cls, data):
|
||||||
if data.get("cache_salt") is not None and (
|
if data.get("cache_salt") is not None and (
|
||||||
not isinstance(data["cache_salt"], str) or not data["cache_salt"]
|
not isinstance(data["cache_salt"], str) or not data["cache_salt"]
|
||||||
):
|
):
|
||||||
raise ValueError(
|
raise VLLMValidationError(
|
||||||
"Parameter 'cache_salt' must be a non-empty string if provided."
|
"Parameter 'cache_salt' must be a non-empty string if provided.",
|
||||||
|
parameter="cache_salt",
|
||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@model_validator(mode="before")
|
@model_validator(mode="before")
|
||||||
|
@classmethod
|
||||||
def function_call_parsing(cls, data):
|
def function_call_parsing(cls, data):
|
||||||
"""Parse function_call dictionaries into ResponseFunctionToolCall objects.
|
"""Parse function_call dictionaries into ResponseFunctionToolCall objects.
|
||||||
This ensures Pydantic can properly resolve union types in the input field.
|
This ensures Pydantic can properly resolve union types in the input field.
|
||||||
|
|||||||
Reference in New Issue
Block a user