Skip to content

Commit 1a24c46

Browse files
authored
server: fix deadly typo in response_format.json_schema.schema handling (#12168)
1 parent becade5 commit 1a24c46

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Diff for: examples/server/tests/unit/test_chat_completion.py

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def test_apply_chat_template():
144144
@pytest.mark.parametrize("response_format,n_predicted,re_content", [
145145
({"type": "json_object", "schema": {"const": "42"}}, 6, "\"42\""),
146146
({"type": "json_object", "schema": {"items": [{"type": "integer"}]}}, 10, "[ -3000 ]"),
147+
({"type": "json_schema", "json_schema": {"schema": {"const": "foooooo"}}}, 10, "\"foooooo\""),
147148
({"type": "json_object"}, 10, "(\\{|John)+"),
148149
({"type": "sound"}, 0, None),
149150
# invalid response format (expected to fail)

Diff for: examples/server/utils.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ static json oaicompat_completion_params_parse(
590590
if (response_type == "json_object") {
591591
json_schema = json_value(response_format, "schema", json::object());
592592
} else if (response_type == "json_schema") {
593-
json json_schema = json_value(response_format, "json_schema", json::object());
594-
json_schema = json_value(json_schema, "schema", json::object());
593+
auto schema_wrapper = json_value(response_format, "json_schema", json::object());
594+
json_schema = json_value(schema_wrapper, "schema", json::object());
595595
} else if (!response_type.empty() && response_type != "text") {
596596
throw std::runtime_error("response_format type must be one of \"text\" or \"json_object\", but got: " + response_type);
597597
}

0 commit comments

Comments
 (0)