-
Notifications
You must be signed in to change notification settings - Fork 399
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
Add JSON
generation method
#140
Merged
rlouf
merged 4 commits into
outlines-dev:main
from
rlouf:generate-schedule-from-json-schema
Aug 14, 2023
Merged
Add JSON
generation method
#140
rlouf
merged 4 commits into
outlines-dev:main
from
rlouf:generate-schedule-from-json-schema
Aug 14, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d128cc4
to
eb4b9f4
Compare
JSON
generation method
d58164c
to
beb3b90
Compare
off topic : would be interesting to see constrained generation of HTML |
Coming with #178 |
e09827d
to
3d66893
Compare
28c8671
to
92495f5
Compare
92495f5
to
8e3e33d
Compare
c39d3eb
to
a2e08ff
Compare
brandonwillard
approved these changes
Aug 14, 2023
b3555cd
to
08dc150
Compare
bb8675c
to
34e4539
Compare
34e4539
to
e1b136f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
In this PR we add a new generation method that can generate valid JSON following a Pydantic mode or JSON Schema specification.
We first parse the (possibly nested) JSON schema into a generation schedule, which is a list of strings that represent the JSON structure, and annotations that correspond to the field specifications. The following annotations are currently supported, with a minimal set of functionalities:
string
int
float
bool
Union[type1, type2]
enum
List[type]
List[Union[type1, type2]]
Optional[type]
maxLength
for stringsminLength
for stringsThe tests demonstrate how to build a schedule from Pydantic models, using the models'
schema_json
method.We also add an
outlines.text.generate.json
function that parses a JSON schema, turns it into a regex and instantiates theRegex
class.