Skip to content

Commit 2e4a6ed

Browse files
pwilkinCISC
andauthored
tools/server: support refusal content for Responses API (ggml-org#20285)
* Support refusal content for Responses API * Update tools/server/server-common.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> * Update tools/server/server-common.cpp Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com> --------- Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
1 parent d34ff7e commit 2e4a6ed

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

tools/server/server-common.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,17 +1273,27 @@ json convert_responses_to_chatcmpl(const json & response_body) {
12731273

12741274
for (const auto & output_text : item.at("content")) {
12751275
const std::string type = json_value(output_text, "type", std::string());
1276-
if (type != "output_text") {
1277-
throw std::invalid_argument("'type' must be 'output_text'");
1278-
}
1279-
if (!exists_and_is_string(output_text, "text")) {
1280-
throw std::invalid_argument("'Output text' requires 'text'");
1276+
if (type == "output_text") {
1277+
if (!exists_and_is_string(output_text, "text")) {
1278+
throw std::invalid_argument("'Output text' requires 'text'");
1279+
// Ignore annotations and logprobs for now
1280+
chatcmpl_content.push_back({
1281+
{"text", output_text.at("text")},
1282+
{"type", "text"},
1283+
});
1284+
}
1285+
} else if (type == "refusal") {
1286+
if (!exists_and_is_string(output_text, "refusal")) {
1287+
throw std::invalid_argument("'Refusal' requires 'refusal'");
1288+
// Ignore annotations and logprobs for now
1289+
chatcmpl_content.push_back({
1290+
{"refusal", output_text.at("refusal")},
1291+
{"type", "refusal"},
1292+
});
1293+
}
1294+
} else {
1295+
throw std::invalid_argument("'type' must be one of 'output_text' or 'refusal'");
12811296
}
1282-
// Ignore annotations and logprobs for now
1283-
chatcmpl_content.push_back({
1284-
{"text", output_text.at("text")},
1285-
{"type", "text"},
1286-
});
12871297
}
12881298

12891299
if (merge_prev) {

0 commit comments

Comments
 (0)