|
4 | 4 | """Unit tests for ResponsesRequest.to_sampling_params() parameter mapping.""" |
5 | 5 |
|
6 | 6 | import pytest |
| 7 | +import torch |
| 8 | +from openai.types.responses.response_format_text_json_schema_config import ( |
| 9 | + ResponseFormatTextJSONSchemaConfig, |
| 10 | +) |
| 11 | +from pydantic import ValidationError |
7 | 12 |
|
8 | | -from vllm.entrypoints.openai.responses.protocol import ResponsesRequest |
| 13 | +from vllm.entrypoints.openai.responses.protocol import ( |
| 14 | + ResponsesRequest, |
| 15 | + ResponseTextConfig, |
| 16 | +) |
| 17 | +from vllm.sampling_params import StructuredOutputsParams |
9 | 18 |
|
10 | 19 |
|
11 | 20 | class TestResponsesRequestSamplingParams: |
@@ -76,9 +85,6 @@ def test_default_values(self): |
76 | 85 |
|
77 | 86 | def test_seed_bounds_validation(self): |
78 | 87 | """Test that seed values outside torch.long bounds are rejected.""" |
79 | | - import torch |
80 | | - from pydantic import ValidationError |
81 | | - |
82 | 88 | # Test seed below minimum |
83 | 89 | with pytest.raises(ValidationError) as exc_info: |
84 | 90 | ResponsesRequest( |
@@ -111,3 +117,40 @@ def test_seed_bounds_validation(self): |
111 | 117 | seed=torch.iinfo(torch.long).max, |
112 | 118 | ) |
113 | 119 | assert request_max.seed == torch.iinfo(torch.long).max |
| 120 | + |
| 121 | + def test_structured_outputs_passed_through(self): |
| 122 | + """Test that structured_outputs field is passed to SamplingParams.""" |
| 123 | + structured_outputs = StructuredOutputsParams(grammar="root ::= 'hello'") |
| 124 | + request = ResponsesRequest( |
| 125 | + model="test-model", |
| 126 | + input="test input", |
| 127 | + structured_outputs=structured_outputs, |
| 128 | + ) |
| 129 | + |
| 130 | + sampling_params = request.to_sampling_params(default_max_tokens=1000) |
| 131 | + |
| 132 | + assert sampling_params.structured_outputs is not None |
| 133 | + assert sampling_params.structured_outputs.grammar == "root ::= 'hello'" |
| 134 | + |
| 135 | + def test_structured_outputs_and_json_schema_conflict(self): |
| 136 | + """Test that specifying both structured_outputs and json_schema raises.""" |
| 137 | + structured_outputs = StructuredOutputsParams(grammar="root ::= 'hello'") |
| 138 | + text_config = ResponseTextConfig() |
| 139 | + text_config.format = ResponseFormatTextJSONSchemaConfig( |
| 140 | + type="json_schema", |
| 141 | + name="test", |
| 142 | + schema={"type": "object"}, |
| 143 | + ) |
| 144 | + request = ResponsesRequest( |
| 145 | + model="test-model", |
| 146 | + input="test input", |
| 147 | + structured_outputs=structured_outputs, |
| 148 | + text=text_config, |
| 149 | + ) |
| 150 | + |
| 151 | + with pytest.raises(ValueError) as exc_info: |
| 152 | + request.to_sampling_params(default_max_tokens=1000) |
| 153 | + |
| 154 | + assert "Cannot specify both structured_outputs and text.format" in str( |
| 155 | + exc_info.value |
| 156 | + ) |
0 commit comments