server: responses api: support conversion of text.format.json_schema to completions (#26145)

This commit is contained in:
Matt Thompson authored and GitHub committed 2026-11-10 00:43:38 +01:00
1 parent 26d52b0f95
commit 711f9f4c11
2 files changed
+77

No files matched your search

+28
View File
@@ -311,6 +311,34 @@ json server_chat_convert_responses_to_chatcmpl(const json & response_body) {
chatcmpl_body.erase("reasoning");
}
if (response_body.contains("text")) {
const json & text = response_body.at("text");
if (!text.is_object()) {
throw std::invalid_argument("'text' must be an object");
}
chatcmpl_body.erase("text");
if (text.contains("format")) {
const json & format = text.at("format");
if (!format.is_object()) {
throw std::invalid_argument("'text.format' must be an object");
}
const std::string type = json_value(format, "type", std::string());
if (type == "json_schema") {
chatcmpl_body["response_format"] = {
{"type", "json_schema"},
{"json_schema", format},
};
chatcmpl_body["response_format"]["json_schema"].erase("type");
} else if (type == "json_object" || type == "text") {
chatcmpl_body["response_format"] = format;
} else if (!type.empty()) {
throw std::invalid_argument("'text.format.type' must be one of 'text', 'json_object', or 'json_schema'");
}
}
}
// llama.cpp params (e.g. seed, min_p) go under extra_params and are merged into the converted body
if (response_body.contains("extra_params")) {
chatcmpl_body.erase("extra_params");