[Feature]Fix order dependency using permutation #474
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When converting a JSON schema to EBNF, there exists an internal order dependency within the schema definition. However, since some fields are optional, it is reasonable for the LLM to generate later optional fields before earlier ones — this behavior should be independent of the definition order.
Take this schema as an example:
As you can see, the converted EBNF does not include an option to generate “age” before “name”!
Modification
Using the same algorithm of converting json_schema to ebnf, but in different orders using permutation.
Results
Version info:
Server: using
SGLangto launch a server.Client:
Before
No age since age comes before the description in the tool definition, once desciption field is generated, it is impossible to generate age later.
After
Limitation
My personal take: This modification isn’t ideal, but it works fine for tools with relatively few arguments. This PR can serve as a quick fix or a reference for those who want to eliminate order dependency.