Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow unconstrained whitespace in JSON schema #123

Merged

Conversation

Ubospica
Copy link
Collaborator

@Ubospica Ubospica commented Dec 7, 2024

This PR supports allowing any whitespace by the grammar converted from JSON schema.

Previously the json_schema_converter only allows strictly formatted JSON schema by specifying the indentation and separators. However, some model could tend to generate unformatted JSON schema. Forcing them to generate strictly formatted json may degrade the output quality, because these models will generate a dummy json following the format constraint.

This PR provides an option any_whitespace in Grammar.from_json_schema and GrammarCompiler.compile_json_schema, default true, to allow any whitespace in the generated json, therefore allowing non-strictly formatted json output.

Note that this PR changes the behavior of these two functions that the converted grammar will by default allow any whitespace, unless a indentation is specifyed.

It also addresses #122.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant