mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-27 21:46:57 +02:00
* server: support input_image in function_call_output (#20663) * server: fix if statement spacing * server: avoid repeated type lookup
This commit is contained in:
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user