server: support input_image in function_call_output (#20663) (#22575)

* server: support input_image in function_call_output (#20663)

* server: fix if statement spacing

* server: avoid repeated type lookup
This commit is contained in:
Empressia
2026-09-22 21:04:58 +02:00
committed by GitHub
parent 4ceb171910
commit 4098fdc922
+17 -3
View File
@@ -203,10 +203,24 @@ json server_chat_convert_responses_to_chatcmpl(const json & response_body) {
} else {
json chatcmpl_outputs = item.at("output");
for (json & chatcmpl_output : chatcmpl_outputs) {
if (!chatcmpl_output.contains("type") || chatcmpl_output.at("type") != "input_text") {
throw std::invalid_argument("Output of tool call should be 'Input text'");
if (!chatcmpl_output.contains("type")) {
throw std::invalid_argument("Output of tool call missing 'type' field");
}
const auto type = chatcmpl_output.at("type");
if (type != "input_text" && type != "input_image") {
throw std::invalid_argument("Output of tool call should be 'Input text' or 'Input image'");
}
if (type == "input_text") {
chatcmpl_output["type"] = "text";
} else if (type == "input_image") {
if (!chatcmpl_output.contains("image_url")) {
throw std::invalid_argument("'image_url' is required");
}
chatcmpl_output["type"] = "image_url";
chatcmpl_output["image_url"] = json {
{"url", chatcmpl_output.at("image_url")}
};
}
chatcmpl_output["type"] = "text";
}
chatcmpl_messages.push_back(json {
{"content", chatcmpl_outputs},