|
39 | 39 | {"custom_id": "request-2", "method": "POST", "url": "/v1/rerank", "body": {"model": "BAAI/bge-reranker-v2-m3", "query": "What is the capital of France?", "documents": ["The capital of Brazil is Brasilia.", "The capital of France is Paris."]}} |
40 | 40 | {"custom_id": "request-2", "method": "POST", "url": "/v2/rerank", "body": {"model": "BAAI/bge-reranker-v2-m3", "query": "What is the capital of France?", "documents": ["The capital of Brazil is Brasilia.", "The capital of France is Paris."]}}""" |
41 | 41 |
|
| 42 | +INPUT_REASONING_BATCH = """{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "Qwen/Qwen3-0.6B", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Solve this math problem: 2+2=?"}]}} |
| 43 | +{"custom_id": "request-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "Qwen/Qwen3-0.6B", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "What is the capital of France?"}]}}""" |
| 44 | + |
42 | 45 |
|
43 | 46 | def test_empty_file(): |
44 | 47 | with ( |
@@ -188,3 +191,50 @@ def test_score(input_batch): |
188 | 191 | line_dict = json.loads(line) |
189 | 192 | assert isinstance(line_dict, dict) |
190 | 193 | assert line_dict["error"] is None |
| 194 | + |
| 195 | + |
| 196 | +def test_reasoning_parser(): |
| 197 | + """ |
| 198 | + Test that reasoning_parser parameter works correctly in run_batch. |
| 199 | + """ |
| 200 | + with ( |
| 201 | + tempfile.NamedTemporaryFile("w") as input_file, |
| 202 | + tempfile.NamedTemporaryFile("r") as output_file, |
| 203 | + ): |
| 204 | + input_file.write(INPUT_REASONING_BATCH) |
| 205 | + input_file.flush() |
| 206 | + proc = subprocess.Popen( |
| 207 | + [ |
| 208 | + "vllm", |
| 209 | + "run-batch", |
| 210 | + "-i", |
| 211 | + input_file.name, |
| 212 | + "-o", |
| 213 | + output_file.name, |
| 214 | + "--model", |
| 215 | + "Qwen/Qwen3-0.6B", |
| 216 | + "--reasoning-parser", |
| 217 | + "qwen3", |
| 218 | + ], |
| 219 | + ) |
| 220 | + proc.communicate() |
| 221 | + proc.wait() |
| 222 | + assert proc.returncode == 0, f"{proc=}" |
| 223 | + |
| 224 | + contents = output_file.read() |
| 225 | + for line in contents.strip().split("\n"): |
| 226 | + # Ensure that the output format conforms to the openai api. |
| 227 | + # Validation should throw if the schema is wrong. |
| 228 | + BatchRequestOutput.model_validate_json(line) |
| 229 | + |
| 230 | + # Ensure that there is no error in the response. |
| 231 | + line_dict = json.loads(line) |
| 232 | + assert isinstance(line_dict, dict) |
| 233 | + assert line_dict["error"] is None |
| 234 | + |
| 235 | + # Check that reasoning_content is present and not empty |
| 236 | + reasoning_content = line_dict["response"]["body"]["choices"][0]["message"][ |
| 237 | + "reasoning_content" |
| 238 | + ] |
| 239 | + assert reasoning_content is not None |
| 240 | + assert len(reasoning_content) > 0 |
0 commit comments