-
Notifications
You must be signed in to change notification settings - Fork 634
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] Support new parameter - EBNF in xgrammar #2526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Can you also support it with the OpenAI API?
sglang/test/srt/test_openai_server.py
Lines 470 to 480 in 19ba2b0
response = client.chat.completions.create( | |
model=self.model, | |
messages=[ | |
{"role": "system", "content": "You are a helpful AI assistant"}, | |
{"role": "user", "content": "Introduce the capital of France."}, | |
], | |
temperature=0, | |
max_tokens=128, | |
extra_body={"regex": regex}, | |
) | |
text = response.choices[0].message.content |
@merrymercy done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It overall looks great for me. Thanks!
Thanks for the contribution! It is merged @adarshxs |
Thank you! |
Motivation
XGrammar enables efficient structured generation. XGrammar backend already support enforcement of EBNF (Extended Backus-Naur Form) grammars.
adds feature requested in: #2376
Modifications
ebnf
in sampling_params.py and treat it similar to regex and JSON.test_ebnf_generate
method to validate multiple valid output patterns based on a complex EBNF grammar.Checklist
TODO: update docs