Update XGrammar to the latest API (#2176)

Co-authored-by: Ben Gitter <gitterbd@gmail.com>
This commit is contained in:
Yixin Dong
2024-11-25 18:58:30 -05:00
committed by GitHub
parent 3c5538f781
commit 7f076c2ce6
3 changed files with 61 additions and 45 deletions

View File

@@ -17,7 +17,7 @@ from sglang.test.test_utils import (
)
class TestJSONConstrained(unittest.TestCase):
class TestJSONConstrainedOutlinesBackend(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.model = DEFAULT_MODEL_NAME_FOR_TEST
@@ -36,7 +36,12 @@ class TestJSONConstrained(unittest.TestCase):
cls.model,
cls.base_url,
timeout=300,
other_args=["--max-running-requests", "10"],
other_args=[
"--max-running-requests",
"10",
"--grammar-backend",
"outlines",
],
)
@classmethod
@@ -121,5 +126,33 @@ class TestJSONConstrained(unittest.TestCase):
list(executor.map(self.run_decode, json_schemas))
class TestJSONConstrainedXGrammarBackend(TestJSONConstrainedOutlinesBackend):
@classmethod
def setUpClass(cls):
cls.model = DEFAULT_MODEL_NAME_FOR_TEST
cls.base_url = DEFAULT_URL_FOR_TEST
cls.json_schema = json.dumps(
{
"type": "object",
"properties": {
"name": {"type": "string"},
"population": {"type": "integer"},
},
"required": ["name", "population"],
}
)
cls.process = popen_launch_server(
cls.model,
cls.base_url,
timeout=300,
other_args=[
"--max-running-requests",
"10",
"--grammar-backend",
"xgrammar",
],
)
if __name__ == "__main__":
unittest.main()