Skip to content

Commit f04dea7

Browse files
authored
Support multimodal on /completions endpoint
- If the 'multimodal_data' field is present, treat each entry in the list as a base64 encoded multimodal data, and append it to the files passed to the completion handler - Just check for mtmd support, and not only openai-emulation, in the completion handler implementation.
1 parent 9515c61 commit f04dea7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/server/server.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4250,7 +4250,7 @@ int main(int argc, char ** argv) {
42504250
// process prompt
42514251
std::vector<server_tokens> inputs;
42524252

4253-
if (oaicompat && has_mtmd) {
4253+
if (has_mtmd) {
42544254
// multimodal
42554255
std::string prompt_str = prompt.get<std::string>();
42564256
mtmd_input_text inp_txt = {
@@ -4369,7 +4369,12 @@ int main(int argc, char ** argv) {
43694369

43704370
const auto handle_completions = [&handle_completions_impl](const httplib::Request & req, httplib::Response & res) {
43714371
json data = json::parse(req.body);
4372-
std::vector<raw_buffer> files; // dummy
4372+
std::vector<raw_buffer> files;
4373+
if (data.find("multimodal_data") != data.end()) {
4374+
for (const auto& entry : data.at("multimodal_data")) {
4375+
files.push_back(base64_decode(entry));
4376+
}
4377+
}
43734378
handle_completions_impl(
43744379
SERVER_TASK_TYPE_COMPLETION,
43754380
data,

0 commit comments

Comments
 (0)