Commit 4098fdc92 for llama.cpp
commit 4098fdc922460470caa12659249e55f77c06730f
Author: Empressia <sphere.soffie@gmail.com>
Date: Wed Sep 23 04:04:58 2026 +0900
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
diff --git a/tools/server/server-chat.cpp b/tools/server/server-chat.cpp
index a6fe3c6ba..a3a4ea152 100644
--- a/tools/server/server-chat.cpp
+++ b/tools/server/server-chat.cpp
@@ -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},