Skip to content

Commit 02f7804

Browse files
committed
fix pre-commit error
Signed-off-by: csy1204 <[email protected]>
1 parent c8e1686 commit 02f7804

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

tests/entrypoints/llm/test_guided_generate.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,26 @@ def test_guided_json_completion_with_enum(llm, guided_decoding_backend: str):
388388

389389
@pytest.mark.skip_global_cleanup
390390
@pytest.mark.parametrize("guided_decoding_backend", GUIDED_DECODING_BACKENDS)
391-
def test_guided_number_range_json_completion(llm, guided_decoding_backend: str):
391+
def test_guided_number_range_json_completion(llm,
392+
guided_decoding_backend: str):
392393
sample_number_range_schema = {
393394
"type": "object",
394395
"properties": {
395-
"age": {"type": "integer", "minimum": 18, "maximum": 99},
396-
"score": {"type": "number", "minimum": 0.0, "maximum": 100.0},
397-
"level": {"type": "integer", "minimum": 1, "maximum": 10},
396+
"age": {
397+
"type": "integer",
398+
"minimum": 18,
399+
"maximum": 99
400+
},
401+
"score": {
402+
"type": "number",
403+
"minimum": 0.0,
404+
"maximum": 100.0
405+
},
406+
"level": {
407+
"type": "integer",
408+
"minimum": 1,
409+
"maximum": 10
410+
},
398411
},
399412
"required": ["age", "score", "level"]
400413
}
@@ -420,7 +433,8 @@ def test_guided_number_range_json_completion(llm, guided_decoding_backend: str):
420433
assert generated_text is not None
421434
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
422435
output_json = json.loads(generated_text)
423-
jsonschema.validate(instance=output_json, schema=sample_number_range_schema)
436+
jsonschema.validate(instance=output_json,
437+
schema=sample_number_range_schema)
424438
assert 18 <= output_json["age"] <= 99
425439
assert 0.0 <= output_json["score"] <= 100.0
426440
assert 1 <= output_json["level"] <= 10
@@ -432,7 +446,10 @@ def test_guided_pattern_json_completion(llm, guided_decoding_backend: str):
432446
sample_pattern_schema = {
433447
"type": "object",
434448
"properties": {
435-
"zipcode": {"type": "string", "pattern": r"^\\d{5}(-\\d{4})?$"},
449+
"zipcode": {
450+
"type": "string",
451+
"pattern": r"^\\d{5}(-\\d{4})?$"
452+
},
436453
},
437454
"required": ["zipcode"]
438455
}
@@ -441,11 +458,10 @@ def test_guided_pattern_json_completion(llm, guided_decoding_backend: str):
441458
guided_decoding=GuidedDecodingParams(
442459
json=sample_pattern_schema,
443460
backend=guided_decoding_backend))
444-
outputs = llm.generate(prompts=[
445-
"Create a JSON object for a US zipcode (5 or 9 digits)."
446-
] * 2,
447-
sampling_params=sampling_params,
448-
use_tqdm=True)
461+
outputs = llm.generate(
462+
prompts=["Create a JSON object for a US zipcode (5 or 9 digits)."] * 2,
463+
sampling_params=sampling_params,
464+
use_tqdm=True)
449465

450466
assert outputs is not None
451467

@@ -459,4 +475,5 @@ def test_guided_pattern_json_completion(llm, guided_decoding_backend: str):
459475
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
460476
output_json = json.loads(generated_text)
461477
jsonschema.validate(instance=output_json, schema=sample_pattern_schema)
462-
assert re.fullmatch(r"^\d{5}(-\d{4})?$", output_json["zipcode"]) is not None
478+
assert re.fullmatch(r"^\d{5}(-\d{4})?$",
479+
output_json["zipcode"]) is not None

tests/v1/entrypoints/llm/test_struct_output_generate.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,21 @@ def test_structured_output_number_range(
425425
number_range_schema = {
426426
"type": "object",
427427
"properties": {
428-
"age": {"type": "integer", "minimum": 18, "maximum": 99},
429-
"score": {"type": "number", "minimum": 0.0, "maximum": 100.0},
430-
"level": {"type": "integer", "minimum": 1, "maximum": 10},
428+
"age": {
429+
"type": "integer",
430+
"minimum": 18,
431+
"maximum": 99
432+
},
433+
"score": {
434+
"type": "number",
435+
"minimum": 0.0,
436+
"maximum": 100.0
437+
},
438+
"level": {
439+
"type": "integer",
440+
"minimum": 1,
441+
"maximum": 10
442+
},
431443
},
432444
"required": ["age", "score", "level"]
433445
}
@@ -475,19 +487,21 @@ def test_structured_output_pattern(
475487
pattern_schema = {
476488
"type": "object",
477489
"properties": {
478-
"zipcode": {"type": "string", "pattern": r"^\\d{5}(-\\d{4})?$"},
490+
"zipcode": {
491+
"type": "string",
492+
"pattern": r"^\\d{5}(-\\d{4})?$"
493+
},
479494
},
480495
"required": ["zipcode"]
481496
}
482497
sampling_params = SamplingParams(
483498
temperature=1.0,
484499
max_tokens=1000,
485500
guided_decoding=GuidedDecodingParams(json=pattern_schema))
486-
outputs = llm.generate(prompts=[
487-
"Create a JSON object for a US zipcode (5 or 9 digits)."
488-
] * 2,
489-
sampling_params=sampling_params,
490-
use_tqdm=True)
501+
outputs = llm.generate(
502+
prompts=["Create a JSON object for a US zipcode (5 or 9 digits)."] * 2,
503+
sampling_params=sampling_params,
504+
use_tqdm=True)
491505

492506
assert outputs is not None
493507
for output in outputs:
@@ -499,4 +513,5 @@ def test_structured_output_pattern(
499513
assert "\n" not in generated_text
500514
output_json = json.loads(generated_text)
501515
jsonschema.validate(instance=output_json, schema=pattern_schema)
502-
assert re.fullmatch(r"^\d{5}(-\d{4})?$", output_json["zipcode"]) is not None
516+
assert re.fullmatch(r"^\d{5}(-\d{4})?$",
517+
output_json["zipcode"]) is not None

0 commit comments

Comments
 (0)