From: Piotr Wilkin (ilintar) Date: Tue, 17 Mar 2026 00:42:04 +0000 (+0100) Subject: tools/server: support refusal content for Responses API (#20285) X-Git-Tag: upstream/0.0.8611~222 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=2e4a6edd4ac6ebb2459fca373249298291acfc5e;p=pkg%2Fggml%2Fsources%2Fllama.cpp tools/server: support refusal content for Responses API (#20285) * Support refusal content for Responses API * Update tools/server/server-common.cpp Co-authored-by: Sigbjørn Skjæret * Update tools/server/server-common.cpp Co-authored-by: Sigbjørn Skjæret --------- Co-authored-by: Sigbjørn Skjæret --- diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index bd203228c..d55987c6d 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -1273,17 +1273,27 @@ json convert_responses_to_chatcmpl(const json & response_body) { for (const auto & output_text : item.at("content")) { const std::string type = json_value(output_text, "type", std::string()); - if (type != "output_text") { - throw std::invalid_argument("'type' must be 'output_text'"); - } - if (!exists_and_is_string(output_text, "text")) { - throw std::invalid_argument("'Output text' requires 'text'"); + if (type == "output_text") { + if (!exists_and_is_string(output_text, "text")) { + throw std::invalid_argument("'Output text' requires 'text'"); + // Ignore annotations and logprobs for now + chatcmpl_content.push_back({ + {"text", output_text.at("text")}, + {"type", "text"}, + }); + } + } else if (type == "refusal") { + if (!exists_and_is_string(output_text, "refusal")) { + throw std::invalid_argument("'Refusal' requires 'refusal'"); + // Ignore annotations and logprobs for now + chatcmpl_content.push_back({ + {"refusal", output_text.at("refusal")}, + {"type", "refusal"}, + }); + } + } else { + throw std::invalid_argument("'type' must be one of 'output_text' or 'refusal'"); } - // Ignore annotations and logprobs for now - chatcmpl_content.push_back({ - {"text", output_text.at("text")}, - {"type", "text"}, - }); } if (merge_prev) {