Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ absl::Status ImageDecodingProcessor::process(InputRequest& req) {
continue;
}

// Accumulate image tags and text parts from a single message's content array.
std::string imageTags;
std::string textContent;
// Flatten multipart content in its original order, replacing each image
// with the placeholder consumed by the VLM pipeline.
std::string flattenedContent;
bool previousPartWasText = false;

for (size_t j = 0; j < content.size(); j++) {
const auto part = content[j];
Expand All @@ -81,17 +82,19 @@ absl::Status ImageDecodingProcessor::process(InputRequest& req) {
return imageResult.status();
}
req.inputImages.push_back(std::move(imageResult).value());
imageTags += "<ov_genai_image_" + std::to_string(imageIndex++) + ">\n";
flattenedContent += "<ov_genai_image_" + std::to_string(imageIndex++) + ">\n";
previousPartWasText = false;
} else if (type == "text") {
if (!textContent.empty()) {
textContent += "\n";
if (previousPartWasText) {
flattenedContent += "\n";
}
textContent += part["text"].as_string().value_or("");
flattenedContent += part["text"].as_string().value_or("");
previousPartWasText = true;
}
}

if (!imageTags.empty() || !textContent.empty()) {
chatHistory[i]["content"] = imageTags + textContent;
if (!flattenedContent.empty()) {
chatHistory[i]["content"] = flattenedContent;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ TEST_P(InputProcessingIntegrationTest, InterleavedTextAndImage_BothTextPartsInPr
ASSERT_TRUE(result.parseStatus.ok()) << result.parseStatus.message();
ASSERT_TRUE(result.processStatus.ok()) << result.processStatus.message();

// [text("Before."), image, text("After.")] → image tag before joined text.
// Preserve the multipart order: [text("Before."), image, text("After.")].
const std::string expected =
std::string(SMOL_DEFAULT_SYSTEM) +
"<|im_start|>user\n<ov_genai_image_0>\nBefore.\nAfter.<|im_end|>\n"
"<|im_start|>user\nBefore.<ov_genai_image_0>\nAfter.<|im_end|>\n"
"<|im_start|>assistant\n";
ASSERT_EQ(result.req.inputImages.size(), 1u);
EXPECT_EQ(result.req.promptText, expected);
Expand Down