Skip to content

Commit 52d082d

Browse files
committed
add new xllamacpp unit test
1 parent 54df2be commit 52d082d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

xinference/model/llm/llama_cpp/tests/test_structured.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,40 @@ def test_apply_response_format_ignores_non_schema(monkeypatch):
6464
_apply_response_format(cfg)
6565
assert "grammar" not in cfg
6666
assert "json_schema" not in cfg
67+
68+
69+
def test_apply_response_format_uses_real_xllamacpp_if_available():
70+
import importlib.util
71+
72+
import pytest
73+
74+
if importlib.util.find_spec("xllamacpp") is None:
75+
pytest.skip("xllamacpp not installed")
76+
77+
import importlib
78+
79+
xllamacpp = importlib.import_module("xllamacpp")
80+
if not hasattr(xllamacpp, "json_schema_to_grammar"):
81+
pytest.skip("xllamacpp does not expose json_schema_to_grammar")
82+
83+
from xinference.model.llm.llama_cpp.core import _apply_response_format
84+
85+
cfg = {
86+
"response_format": {
87+
"type": "json_schema",
88+
"json_schema": {
89+
"schema": {
90+
"type": "object",
91+
"properties": {"c": {"type": "integer"}},
92+
"required": ["c"],
93+
}
94+
},
95+
}
96+
}
97+
98+
_apply_response_format(cfg)
99+
100+
assert "response_format" not in cfg
101+
# Real xllamacpp should attach grammar alongside json_schema
102+
assert "json_schema" in cfg
103+
assert "grammar" in cfg and cfg["grammar"]

0 commit comments

Comments
 (0)