]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
examples : fix empty items in json_schema_to_grammar.py [no ci] (#19968)
authorRay Xu <redacted>
Tue, 10 Mar 2026 13:38:18 +0000 (21:38 +0800)
committerGitHub <redacted>
Tue, 10 Mar 2026 13:38:18 +0000 (14:38 +0100)
commit8d880ac012003de6fcddff0e9108e75703e68d8a
tree0e375be78b9ef44fe8bcff84610854cd8964b86e
parent0f1e9d14cc716e3d42728d5181b1b4f93c71bfa3
examples : fix empty items in json_schema_to_grammar.py [no ci] (#19968)

* Fix logic for retrieving schema items in `json_schema_to_grammar.py`

If `schema['items']` is `{}` and `prefixItems not in schema', as `{}` is Falsy, the original code here will raise an error.

I think if `schema['items']` is `{}`, them items should just be `{}`

* Apply suggestion from @CISC

Co-authored-by: Sigbjørn Skjæret <redacted>
* Add tests for arrays with empty items

Add two unit tests to `tests/test-json-schema-to-grammar.cpp` that validate handling of arrays when 'items' is an empty schema and when 'prefixItems' is present alongside an empty 'items'. Both tests expect the same generated grammar, ensuring the JSON Schema->grammar conversion treats an empty 'items' schema (and the presence of 'prefixItems') correctly and covering this edge case.

---------

Co-authored-by: Sigbjørn Skjæret <redacted>
examples/json_schema_to_grammar.py
tests/test-json-schema-to-grammar.cpp