Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tools/server/server-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3710,14 +3710,17 @@ void server_routes::init_routes() {
if (data.contains("prompt") && !data.at("prompt").is_string()) {
// prompt is optional
res->error(format_error_response("\"prompt\" must be a string", ERROR_TYPE_INVALID_REQUEST));
return res;
}

if (!data.contains("input_prefix")) {
res->error(format_error_response("\"input_prefix\" is required", ERROR_TYPE_INVALID_REQUEST));
return res;
}

if (!data.contains("input_suffix")) {
res->error(format_error_response("\"input_suffix\" is required", ERROR_TYPE_INVALID_REQUEST));
return res;
}

if (data.contains("input_extra") && !data.at("input_extra").is_array()) {
Expand Down
13 changes: 13 additions & 0 deletions tools/server/tests/unit/test_infill.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ def test_invalid_input_extra_req(input_extra):
assert "error" in res.body


@pytest.mark.parametrize("data,expected_msg", [
({"input_suffix": "}\n"}, "input_prefix"),
({"input_prefix": "#include <cstdio>\n"}, "input_suffix"),
({"prompt": 123, "input_prefix": "a", "input_suffix": "b"}, "prompt"),
])
def test_infill_missing_required_field(data, expected_msg):
global server
server.start()
res = server.make_request("POST", "/infill", data=data)
assert res.status_code == 400
assert expected_msg in res.body["error"]["message"]


@pytest.mark.skipif(not is_slow_test_allowed(), reason="skipping slow test")
def test_with_qwen_model():
global server
Expand Down