Support non-strict GLM47 tool calls with EBNF constraints (#38890)
Co-authored-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
This commit is contained in:
co-authored by
Xinyuan Tong
parent
2c0a70960c
commit
17ba2c2e7c
@@ -13,6 +13,7 @@
|
||||
# ==============================================================================
|
||||
"""Tests for OpenAI API protocol models"""
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -116,6 +117,31 @@ class TestCompletionRequest(unittest.TestCase):
|
||||
class TestChatCompletionRequest(unittest.TestCase):
|
||||
"""Test ChatCompletionRequest protocol model"""
|
||||
|
||||
def test_full_assistant_ebnf_preserves_explicit_output_constraints(self):
|
||||
constraint = ("full_assistant_ebnf", 'root ::= "generated"')
|
||||
for explicit in (
|
||||
{},
|
||||
{"ebnf": 'root ::= "OK"'},
|
||||
{"response_format": {"type": "json_object"}},
|
||||
):
|
||||
with self.subTest(explicit=explicit):
|
||||
request = ChatCompletionRequest(
|
||||
model="test",
|
||||
messages=[{"role": "user", "content": "Hi"}],
|
||||
tool_choice="required",
|
||||
**explicit,
|
||||
)
|
||||
params = request.to_sampling_params([], {}, constraint)
|
||||
self.assertEqual(params.get("ebnf_full_assistant", False), not explicit)
|
||||
if "ebnf" in explicit:
|
||||
self.assertEqual(params["ebnf"], explicit["ebnf"])
|
||||
elif "response_format" in explicit:
|
||||
self.assertEqual(
|
||||
json.loads(params["json_schema"]), {"type": "object"}
|
||||
)
|
||||
else:
|
||||
self.assertEqual(params["ebnf"], constraint[1])
|
||||
|
||||
def test_json_schema_strict_requires_json_boolean(self):
|
||||
base_request = {
|
||||
"model": "test-model",
|
||||
|
||||
Reference in New Issue
Block a user