mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-05-24 22:44:30 +08:00
Updated xgrammar backend to not deny supported string formats (#27253)
Signed-off-by: CNE Pierre FICHEPOIL <pierre-1.fichepoil@gendarmerie.interieur.gouv.fr> Signed-off-by: ExtReMLapin <3909752+ExtReMLapin@users.noreply.github.com> Co-authored-by: CNE Pierre FICHEPOIL <pierre-1.fichepoil@gendarmerie.interieur.gouv.fr> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
parent
344a0017c0
commit
4a8a567e16
@ -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():
|
|||||||
"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):
|
|||||||
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:
|
|||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user