Skip to content

Commit a7d9b7b

Browse files
committed
fix: fix conftest & remove redundant v1 tests
Signed-off-by: csy1204 <[email protected]>
1 parent 3e3fce1 commit a7d9b7b

File tree

2 files changed

+55
-183
lines changed

2 files changed

+55
-183
lines changed

tests/v1/entrypoints/conftest.py

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ def sample_json_schema():
4545
"type": "array",
4646
"items": {
4747
"type": "string",
48-
},
48+
}
49+
},
50+
"grade": {
51+
"type": "string",
52+
"pattern": "^[A-D]$" # Regex pattern
53+
},
54+
"email": {
55+
"type": "string",
56+
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
4957
},
5058
"work_history": {
5159
"type": "array",
@@ -56,17 +64,20 @@ def sample_json_schema():
5664
"type": "string"
5765
},
5866
"duration": {
59-
"type": "number"
67+
"type": "number",
68+
"minimum": 0.0,
69+
"maximum": 100.0, # Numeric range
6070
},
6171
"position": {
6272
"type": "string"
63-
},
73+
}
6474
},
65-
"required": ["company", "position"],
66-
},
67-
},
75+
"required": ["company", "duration", "position"]
76+
}
77+
}
6878
},
69-
"required": ["name", "age", "skills", "work_history"],
79+
"required":
80+
["name", "age", "skills", "grade", "email", "work_history"]
7081
}
7182

7283

@@ -78,84 +89,65 @@ def unsupported_json_schema():
7889
"properties": {
7990
"score": {
8091
"type": "integer",
81-
"minimum": 0,
82-
"maximum": 100, # Numeric range
83-
},
84-
"grade": {
85-
"type": "string",
86-
"pattern": "^[A-D]$", # Regex pattern
87-
},
88-
"email": {
89-
"type": "string",
90-
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
92+
"multipleOf": 5 # Numeric multiple
9193
},
9294
"tags": {
9395
"type": "array",
9496
"items": {
9597
"type": "string",
96-
"pattern": "^[a-z]{1,10}$",
97-
# Combining length and pattern restrictions
98-
"minLength": 1,
99-
"maxLength": 10,
100-
},
101-
},
98+
"minLength": 10,
99+
"maxLength": 20
100+
}
101+
}
102102
},
103-
"required": ["score", "grade", "email", "tags"],
103+
"required": ["score", "tags"]
104104
}
105105

106106

107107
@pytest.fixture
108108
def sample_definition_json_schema():
109109
return {
110-
"$defs": {
111-
"Step": {
112-
"properties": {
113-
"explanation": {
114-
"title": "Explanation",
115-
"type": "string"
116-
},
117-
"output": {
118-
"title": "Output",
119-
"type": "string"
110+
'$defs': {
111+
'Step': {
112+
'properties': {
113+
'explanation': {
114+
'title': 'Explanation',
115+
'type': 'string'
120116
},
117+
'output': {
118+
'title': 'Output',
119+
'type': 'string'
120+
}
121121
},
122-
"required": ["explanation", "output"],
123-
"title": "Step",
124-
"type": "object",
122+
'required': ['explanation', 'output'],
123+
'title': 'Step',
124+
'type': 'object'
125125
}
126126
},
127-
"properties": {
128-
"steps": {
129-
"items": {
130-
"$ref": "#/$defs/Step"
127+
'properties': {
128+
'steps': {
129+
'items': {
130+
'$ref': '#/$defs/Step'
131131
},
132-
"title": "Steps",
133-
"type": "array",
134-
},
135-
"final_answer": {
136-
"title": "Final Answer",
137-
"type": "string"
132+
'title': 'Steps',
133+
'type': 'array'
138134
},
135+
'final_answer': {
136+
'title': 'Final Answer',
137+
'type': 'string'
138+
}
139139
},
140-
"required": ["steps", "final_answer"],
141-
"title": "MathReasoning",
142-
"type": "object",
140+
'required': ['steps', 'final_answer'],
141+
'title': 'MathReasoning',
142+
'type': 'object'
143143
}
144144

145145

146146
@pytest.fixture
147147
def sample_guided_choice():
148148
return [
149-
"Python",
150-
"Java",
151-
"JavaScript",
152-
"C++",
153-
"C#",
154-
"PHP",
155-
"TypeScript",
156-
"Ruby",
157-
"Swift",
158-
"Kotlin",
149+
"Python", "Java", "JavaScript", "C++", "C#", "PHP", "TypeScript",
150+
"Ruby", "Swift", "Kotlin"
159151
]
160152

161153

@@ -173,11 +165,11 @@ def sample_sql_ebnf():
173165

174166
@pytest.fixture
175167
def sample_sql_lark():
176-
return """
168+
return ("""
177169
start: select_statement
178170
select_statement: "SELECT" column "from" table "where" condition
179171
column: "col_1" | "col_2"
180172
table: "table_1" | "table_2"
181173
condition: column "=" number
182174
number: "1" | "2"
183-
"""
175+
""")

tests/v1/entrypoints/llm/test_struct_output_generate.py

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -403,124 +403,4 @@ def test_structured_output_auto_mode(
403403

404404
# Parse to verify it is valid JSON
405405
parsed_json = json.loads(generated_text)
406-
assert isinstance(parsed_json, dict)
407-
408-
409-
@pytest.mark.skip_global_cleanup
410-
@pytest.mark.parametrize(
411-
"model_name, guided_decoding_backend, tokenizer_mode",
412-
PARAMS_MODELS_BACKENDS_TOKENIZER_MODE,
413-
)
414-
def test_structured_output_number_range(
415-
monkeypatch: pytest.MonkeyPatch,
416-
guided_decoding_backend: str,
417-
tokenizer_mode: str,
418-
model_name: str,
419-
):
420-
monkeypatch.setenv("VLLM_USE_V1", "1")
421-
llm = LLM(
422-
model=model_name,
423-
enforce_eager=True,
424-
max_model_len=1024,
425-
guided_decoding_backend=guided_decoding_backend,
426-
tokenizer_mode=tokenizer_mode,
427-
)
428-
429-
number_range_schema = {
430-
"type": "object",
431-
"properties": {
432-
"age": {
433-
"type": "integer",
434-
"minimum": 18,
435-
"maximum": 99
436-
},
437-
"score": {
438-
"type": "number",
439-
"minimum": 0.0,
440-
"maximum": 100.0
441-
},
442-
"level": {
443-
"type": "integer",
444-
"minimum": 1,
445-
"maximum": 10
446-
},
447-
},
448-
"required": ["age", "score", "level"],
449-
}
450-
sampling_params = SamplingParams(
451-
temperature=1.0,
452-
max_tokens=1000,
453-
guided_decoding=GuidedDecodingParams(json=number_range_schema),
454-
)
455-
outputs = llm.generate(
456-
prompts=[
457-
"Create a JSON object for a user with age, score, and level."
458-
] * 2,
459-
sampling_params=sampling_params,
460-
use_tqdm=True,
461-
)
462-
463-
assert outputs is not None
464-
for output in outputs:
465-
assert output is not None
466-
assert isinstance(output, RequestOutput)
467-
generated_text = output.outputs[0].text
468-
assert generated_text is not None
469-
output_json = json.loads(generated_text)
470-
jsonschema.validate(instance=output_json, schema=number_range_schema)
471-
assert 18 <= output_json["age"] <= 99
472-
assert 0.0 <= output_json["score"] <= 100.0
473-
assert 1 <= output_json["level"] <= 10
474-
475-
476-
@pytest.mark.skip_global_cleanup
477-
@pytest.mark.parametrize(
478-
"model_name, guided_decoding_backend, tokenizer_mode",
479-
PARAMS_MODELS_BACKENDS_TOKENIZER_MODE,
480-
)
481-
def test_structured_output_pattern(
482-
monkeypatch: pytest.MonkeyPatch,
483-
guided_decoding_backend: str,
484-
tokenizer_mode: str,
485-
model_name: str,
486-
):
487-
monkeypatch.setenv("VLLM_USE_V1", "1")
488-
llm = LLM(
489-
model=model_name,
490-
enforce_eager=True,
491-
max_model_len=1024,
492-
guided_decoding_backend=guided_decoding_backend,
493-
tokenizer_mode=tokenizer_mode,
494-
)
495-
496-
pattern_schema = {
497-
"type": "object",
498-
"properties": {
499-
"zipcode": {
500-
"type": "string",
501-
"pattern": r"^\d{5}(-\d{4})?$"
502-
},
503-
},
504-
"required": ["zipcode"],
505-
}
506-
sampling_params = SamplingParams(
507-
temperature=1.0,
508-
max_tokens=1000,
509-
guided_decoding=GuidedDecodingParams(json=pattern_schema),
510-
)
511-
outputs = llm.generate(
512-
prompts=["Create a JSON object for a US zipcode (5 or 9 digits)."] * 2,
513-
sampling_params=sampling_params,
514-
use_tqdm=True,
515-
)
516-
517-
assert outputs is not None
518-
for output in outputs:
519-
assert output is not None
520-
assert isinstance(output, RequestOutput)
521-
generated_text = output.outputs[0].text
522-
assert generated_text is not None
523-
output_json = json.loads(generated_text)
524-
jsonschema.validate(instance=output_json, schema=pattern_schema)
525-
assert (re.fullmatch(r"^\d{5}(-\d{4})?$", output_json["zipcode"])
526-
is not None)
406+
assert isinstance(parsed_json, dict)

0 commit comments

Comments
 (0)