[Frontend] Migrate Responses API validation errors to VLLMValidationError (#50257)
Signed-off-by: shaolila <shaolila@buaa.edu.cn> Co-authored-by: shaolila <shaolila@buaa.edu.cn>
This commit is contained in:
@@ -20,6 +20,7 @@ from vllm.entrypoints.openai.responses.harmony import (
|
||||
response_input_to_harmony,
|
||||
response_previous_input_to_harmony,
|
||||
)
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
|
||||
_TOOL_PARAMETERS = {
|
||||
"type": "object",
|
||||
@@ -975,10 +976,11 @@ class TestGetSystemMessage:
|
||||
|
||||
def test_unsupported_reasoning_effort_raises_clear_error(self) -> None:
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
VLLMValidationError,
|
||||
match="reasoning_effort='max' is not supported by Harmony",
|
||||
):
|
||||
) as exc_info:
|
||||
get_system_message(reasoning_effort="max")
|
||||
assert exc_info.value.parameter == "reasoning_effort"
|
||||
|
||||
|
||||
class TestResponseInputToHarmonyReasoningItem:
|
||||
|
||||
@@ -22,6 +22,7 @@ from vllm.entrypoints.openai.responses.utils import (
|
||||
construct_input_messages,
|
||||
should_continue_final_message,
|
||||
)
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
|
||||
|
||||
def _single_chat_message(item):
|
||||
@@ -223,8 +224,9 @@ class TestResponsesUtils:
|
||||
encrypted_content="TOP_SECRET_MESSAGE",
|
||||
status=None,
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(VLLMValidationError) as exc_info:
|
||||
construct_chat_messages_with_tool_call([item])
|
||||
assert exc_info.value.parameter == "input"
|
||||
|
||||
output_item = ResponseOutputMessage(
|
||||
id="msg_bf585bbbe3d500e0",
|
||||
@@ -350,7 +352,7 @@ class TestReasoningItemContentPriority:
|
||||
assert formatted["reasoning"] == ""
|
||||
|
||||
def test_encrypted_content_raises(self):
|
||||
"""Encrypted content should still raise ValueError."""
|
||||
"""Encrypted content should raise VLLMValidationError."""
|
||||
item = ResponseReasoningItem(
|
||||
id="reasoning_6",
|
||||
summary=[
|
||||
@@ -369,8 +371,9 @@ class TestReasoningItemContentPriority:
|
||||
encrypted_content="ENCRYPTED",
|
||||
status=None,
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(VLLMValidationError) as exc_info:
|
||||
construct_chat_messages_with_tool_call([item])
|
||||
assert exc_info.value.parameter == "input"
|
||||
|
||||
@patch("vllm.entrypoints.openai.responses.utils.logger")
|
||||
def test_summary_with_multiple_entries_uses_first(self, mock_logger):
|
||||
|
||||
@@ -24,6 +24,7 @@ from openai_harmony import (
|
||||
|
||||
from vllm import envs
|
||||
from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionToolsParam
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.logger import init_logger
|
||||
|
||||
logger = init_logger(__name__)
|
||||
@@ -123,9 +124,10 @@ def get_system_message(
|
||||
if reasoning_effort is not None:
|
||||
if reasoning_effort not in REASONING_EFFORT:
|
||||
supported_values = ", ".join(REASONING_EFFORT)
|
||||
raise ValueError(
|
||||
raise VLLMValidationError(
|
||||
f"reasoning_effort={reasoning_effort!r} is not supported by "
|
||||
f"Harmony. Supported values are: {supported_values}."
|
||||
f"Harmony. Supported values are: {supported_values}.",
|
||||
parameter="reasoning_effort",
|
||||
)
|
||||
sys_msg_content = sys_msg_content.with_reasoning_effort(
|
||||
REASONING_EFFORT[reasoning_effort]
|
||||
@@ -181,7 +183,10 @@ def get_developer_message(
|
||||
elif tool.type == "function":
|
||||
function_tools.append(tool)
|
||||
else:
|
||||
raise ValueError(f"tool type {tool.type} not supported")
|
||||
raise VLLMValidationError(
|
||||
f"tool type {tool.type!r} is not supported.",
|
||||
parameter="tools",
|
||||
)
|
||||
if function_tools:
|
||||
function_tool_descriptions = [
|
||||
create_tool_definition(tool) for tool in function_tools
|
||||
@@ -297,7 +302,10 @@ def extract_instructions_from_messages(
|
||||
elif hasattr(first_message, "model_dump"):
|
||||
first_message = first_message.model_dump(exclude_none=True)
|
||||
else:
|
||||
raise ValueError(f"Unknown message type: {type(first_message)}")
|
||||
raise VLLMValidationError(
|
||||
f"Unknown message type: {type(first_message)}",
|
||||
parameter="input",
|
||||
)
|
||||
|
||||
if first_message.get("role") not in (
|
||||
"system",
|
||||
|
||||
@@ -37,6 +37,7 @@ from vllm.entrypoints.openai.chat_completion.protocol import (
|
||||
ChatCompletionToolsParam,
|
||||
)
|
||||
from vllm.entrypoints.openai.responses.protocol import ResponseInputOutputItem
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.logger import init_logger
|
||||
from vllm.tool_parsers.utils import (
|
||||
build_responses_tool_call_name_map,
|
||||
@@ -273,7 +274,10 @@ def _construct_message_from_response_item(
|
||||
elif isinstance(item, ResponseReasoningItem):
|
||||
reasoning = ""
|
||||
if item.encrypted_content:
|
||||
raise ValueError("Encrypted content is not supported.")
|
||||
raise VLLMValidationError(
|
||||
"Encrypted content is not supported.",
|
||||
parameter="input",
|
||||
)
|
||||
elif item.content and len(item.content) >= 1:
|
||||
reasoning = item.content[0].text
|
||||
elif len(item.summary) >= 1:
|
||||
|
||||
Reference in New Issue
Block a user