From: Olivier Chafik Date: Tue, 4 Mar 2025 06:24:07 +0000 (+0000) Subject: `server`: fix deadly typo in response_format.json_schema.schema handling (#12168) X-Git-Tag: upstream/0.0.4853~33 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=1a24c4621f0280306b0d53a4fa474fc65d3f1b2e;p=pkg%2Fggml%2Fsources%2Fllama.cpp `server`: fix deadly typo in response_format.json_schema.schema handling (#12168) --- diff --git a/examples/server/tests/unit/test_chat_completion.py b/examples/server/tests/unit/test_chat_completion.py index af1dcb5b..491cb3a5 100644 --- a/examples/server/tests/unit/test_chat_completion.py +++ b/examples/server/tests/unit/test_chat_completion.py @@ -144,6 +144,7 @@ def test_apply_chat_template(): @pytest.mark.parametrize("response_format,n_predicted,re_content", [ ({"type": "json_object", "schema": {"const": "42"}}, 6, "\"42\""), ({"type": "json_object", "schema": {"items": [{"type": "integer"}]}}, 10, "[ -3000 ]"), + ({"type": "json_schema", "json_schema": {"schema": {"const": "foooooo"}}}, 10, "\"foooooo\""), ({"type": "json_object"}, 10, "(\\{|John)+"), ({"type": "sound"}, 0, None), # invalid response format (expected to fail) diff --git a/examples/server/utils.hpp b/examples/server/utils.hpp index 6830c2e1..144d914c 100644 --- a/examples/server/utils.hpp +++ b/examples/server/utils.hpp @@ -590,8 +590,8 @@ static json oaicompat_completion_params_parse( if (response_type == "json_object") { json_schema = json_value(response_format, "schema", json::object()); } else if (response_type == "json_schema") { - json json_schema = json_value(response_format, "json_schema", json::object()); - json_schema = json_value(json_schema, "schema", json::object()); + auto schema_wrapper = json_value(response_format, "json_schema", json::object()); + json_schema = json_value(schema_wrapper, "schema", json::object()); } else if (!response_type.empty() && response_type != "text") { throw std::runtime_error("response_format type must be one of \"text\" or \"json_object\", but got: " + response_type); }