review: docs section, 1 MiB grammar pre-check, negative tests, measured compile overhead
Addresses the #192 review: server usage documented in docs/grammar-draft.md (incl. back-compat statement for the additive SUBMIT field and the #100-class near-tie caveat); gateway pre-checks grammar payloads at 1 MiB (matching the engine's gbytes bound); negative tests for non-dict response_format, empty and oversized grammars, plus an explicit test that malformed GBNF passes the gateway by design (engine fail-soft, draft-source semantics). Measured compile overhead: 7.8 us/request typical schema, 17.9 us at the 32-level nesting cap. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -468,6 +468,9 @@ def generation_options(body, limit):
|
||||
raise APIError(400, "`response_format.type` must be \"text\", \"json_object\", "
|
||||
"\"json_schema\" or \"gbnf\".",
|
||||
"response_format", "unsupported_value")
|
||||
if grammar is not None and len(grammar.encode("utf-8")) > (1 << 20):
|
||||
raise APIError(400, "`response_format` grammar/schema exceeds 1 MiB.",
|
||||
"response_format", "invalid_value")
|
||||
|
||||
maximum = body.get("max_completion_tokens")
|
||||
maximum_param = "max_completion_tokens"
|
||||
|
||||
Reference in New Issue
Block a user