-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Description
currently xgrammar does not support json schema with the following constraints:
xgrammar/cpp/json_schema_converter.cc
Lines 975 to 992 in c1b6492
| std::string JSONSchemaConverter::VisitArray( | |
| const picojson::object& schema, const std::string& rule_name | |
| ) { | |
| XGRAMMAR_CHECK( | |
| (schema.count("type") && schema.at("type").get<std::string>() == "array") || | |
| schema.count("items") || schema.count("prefixItems") || schema.count("unevaluatedItems") | |
| ); | |
| WarnUnsupportedKeywords( | |
| schema, | |
| { | |
| "uniqueItems", | |
| "contains", | |
| "minContains", | |
| "maxContains", | |
| "minItems", | |
| "maxItems", | |
| } | |
| ); |
reproducing the issue
with vllm/vllm-openai:v0.6.6.post1 docker image:
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="-",
)
class Person(BaseModel):
names: list[str]: Field(..., min_length=2, max_length=2)
print(Person.model_json_schema()) # {'properties': {'names': {'items': {'type': 'string'}, 'maxItems': 2, 'minItems': 2, 'title': 'Names', 'type': 'array'}}, 'required': ['names'], 'title': 'Person', 'type': 'object'}
response = client.chat.completions.create(
model='aya-23-35b',
messages=[
{
'role': 'user',
'content': 'Generate 4 names. Respond in json format.'
}
],
extra_body={"guided_json": Person.model_json_schema()}
)
print(response.choices[0].message.content)- 2 names should be generated due to JSON constraint, but 4 names is still generated
pavel-esir and Fogapod
Metadata
Metadata
Assignees
Labels
No labels