[Fix] Work around xgrammar 0.2.1 negative integer minimum in Kimi-K3 structural tags (#34778)
Co-authored-by: James Liu <jamesl@modal.com>
This commit is contained in:
@@ -379,6 +379,39 @@ def test_strict_schema_handles_number_enums_and_all_of_integer_constraints():
|
||||
)
|
||||
|
||||
|
||||
def test_strict_schema_handles_one_sided_negative_integer_minimum():
|
||||
tool = Tool(
|
||||
type="function",
|
||||
function=Function(
|
||||
name="submit",
|
||||
strict=True,
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "integer",
|
||||
"minimum": -1000000,
|
||||
}
|
||||
},
|
||||
"required": ["value"],
|
||||
"additionalProperties": False,
|
||||
},
|
||||
),
|
||||
)
|
||||
grammar = _grammar([tool], tool_choice="required")
|
||||
|
||||
for value in ("-1000000", "-999999", "-1", "0", "1000001"):
|
||||
assert _accepts(
|
||||
grammar,
|
||||
_tools_section(_call("submit", 1, _argument("value", "number", value))),
|
||||
)
|
||||
for value in ("-", "-1000001", "1.5"):
|
||||
assert not _accepts(
|
||||
grammar,
|
||||
_tools_section(_call("submit", 1, _argument("value", "number", value))),
|
||||
)
|
||||
|
||||
|
||||
def test_strict_schema_preserves_additional_properties_default():
|
||||
tool = Tool(
|
||||
type="function",
|
||||
|
||||
Reference in New Issue
Block a user