Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/test_lmdeploy/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,34 @@ def test_guided_matrix(model_id, backend_name, backend_factory, schema_type):
assert re.fullmatch(schema, response[0].text)
finally:
pipe.close()


@pytest.mark.parametrize('model_id', MODEL_IDS)
@pytest.mark.parametrize('backend_name,backend_factory', BACKEND_FACTORIES)
def test_mix_guided_matrix(model_id, backend_name, backend_factory):
pipe = pipeline(
model_id,
backend_config=backend_factory(),
log_level='INFO',
)

schema_type = 'json_schema'
response_format = {'type': schema_type}
schema = SCHEMA_MAP[schema_type]
response_format[schema_type] = dict(name='test', schema=schema)

prompts = ['Make a self introduction please.'] * 4
try:
config = GenerationConfig(response_format=response_format)

gen_config = [None if idx % 3 else config for idx in range(4)]

responses = pipe.batch_infer(prompts, gen_config=gen_config)

for resp, c in zip(responses, gen_config):
if c is None:
assert '}' not in resp.text
else:
validate(instance=json.loads(resp.text), schema=schema)
finally:
pipe.close()