Unverified Commit 4a8a567e authored by ExtReMLapin's avatar ExtReMLapin Committed by GitHub
Browse files
parent 344a0017
...@@ -13,7 +13,7 @@ pytestmark = pytest.mark.cpu_test ...@@ -13,7 +13,7 @@ pytestmark = pytest.mark.cpu_test
@pytest.fixture @pytest.fixture
def unsupported_string_schemas(): def unsupported_string_schemas():
return [ return [
{"type": "string", "format": "email"}, {"type": "string", "format": "non_existing_format"},
] ]
...@@ -58,6 +58,7 @@ def supported_schema(): ...@@ -58,6 +58,7 @@ def supported_schema():
"properties": { "properties": {
"name": {"type": "string"}, "name": {"type": "string"},
"age": {"type": "integer"}, "age": {"type": "integer"},
"email": {"type": "string", "format": "email"},
"status": {"type": "string"}, "status": {"type": "string"},
"scores": {"type": "array", "items": {"type": "number"}}, "scores": {"type": "array", "items": {"type": "number"}},
"car_type": {"type": "string", "enum": ["sedan", "suv", "truck"]}, "car_type": {"type": "string", "enum": ["sedan", "suv", "truck"]},
......
...@@ -200,6 +200,25 @@ class XgrammarGrammar(StructuredOutputGrammar): ...@@ -200,6 +200,25 @@ class XgrammarGrammar(StructuredOutputGrammar):
self.matcher.reset() self.matcher.reset()
# cf https://github.com/mlc-ai/xgrammar/blob/a32ac892676d2eedc0327416105b9b06edfb94b2/cpp/json_schema_converter.cc
STRING_SUPPORTED_FORMATS = {
"email",
"date",
"time",
"date-time",
"duration",
"ipv4",
"ipv6",
"hostname",
"uuid",
"uri",
"uri-reference",
"uri-template",
"json-pointer",
"relative-json-pointer",
}
def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool: def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
"""Check if JSON schema contains features unsupported by xgrammar.""" """Check if JSON schema contains features unsupported by xgrammar."""
...@@ -219,7 +238,11 @@ def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool: ...@@ -219,7 +238,11 @@ def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
return True return True
# Unsupported keywords for strings # Unsupported keywords for strings
if obj.get("type") == "string" and "format" in obj: if (
obj.get("type") == "string"
and "format" in obj
and obj["format"] not in STRING_SUPPORTED_FORMATS
):
return True return True
# Unsupported keywords for objects # Unsupported keywords for objects
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment