Skip to content

Commit 315c3b2

Browse files
Pass plugin config to vlm legacy pipeline (#3291)
1 parent da8e03d commit 315c3b2

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

src/llm/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ cc_library(
7979
"@mediapipe//mediapipe/framework:calculator_framework", # required for absl status
8080
"//src:libovmsprofiler",
8181
"//third_party:curl",
82+
"//src:libovmsfilesystem",
8283
"@stb//:image",
8384
] + select({
8485
"//conditions:default": ["//third_party:genai", ":llm_engine"],

src/llm/apis/openai_completions.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define STB_IMAGE_IMPLEMENTATION
2727
#include "../../logging.hpp"
2828
#include "../../profiler.hpp"
29+
#include "../../filesystem.hpp"
2930
#pragma warning(push)
3031
#pragma warning(disable : 6262)
3132
#include "stb_image.h" // NOLINT
@@ -248,7 +249,7 @@ absl::Status OpenAIChatCompletionsHandler::parseMessages(std::optional<std::stri
248249
} catch (std::runtime_error& e) {
249250
std::stringstream ss;
250251
ss << "Image parsing failed: " << e.what();
251-
SPDLOG_LOGGER_ERROR(llm_calculator_logger, ss.str());
252+
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, ss.str());
252253
return absl::InvalidArgumentError(ss.str());
253254
}
254255
} else if (std::regex_match(url.c_str(), std::regex("^(http|https|ftp|sftp|)://(.*)"))) {
@@ -264,14 +265,20 @@ absl::Status OpenAIChatCompletionsHandler::parseMessages(std::optional<std::stri
264265
} catch (std::runtime_error& e) {
265266
std::stringstream ss;
266267
ss << "Image parsing failed: " << e.what();
267-
SPDLOG_LOGGER_ERROR(llm_calculator_logger, ss.str());
268+
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, ss.str());
268269
return absl::InvalidArgumentError("Image parsing failed");
269270
}
270271

271272
} else {
272273
if (!allowedLocalMediaPath.has_value()) {
273274
return absl::InvalidArgumentError("Loading images from local filesystem is disabled.");
274275
}
276+
if (FileSystem::isPathEscaped(url)) {
277+
std::stringstream ss;
278+
ss << "Path " << url.c_str() << " escape with .. is forbidden.";
279+
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, ss.str());
280+
return absl::InvalidArgumentError(ss.str());
281+
}
275282
SPDLOG_LOGGER_TRACE(llm_calculator_logger, "Loading image from local filesystem");
276283
const auto firstMissmatch = std::mismatch(url.begin(), url.end(), allowedLocalMediaPath.value().begin(), allowedLocalMediaPath.value().end());
277284
if (firstMissmatch.second != allowedLocalMediaPath.value().end()) {
@@ -282,7 +289,7 @@ absl::Status OpenAIChatCompletionsHandler::parseMessages(std::optional<std::stri
282289
} catch (std::runtime_error& e) {
283290
std::stringstream ss;
284291
ss << "Image file " << url.c_str() << " parsing failed: " << e.what();
285-
SPDLOG_LOGGER_ERROR(llm_calculator_logger, ss.str());
292+
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, ss.str());
286293
return absl::InvalidArgumentError(ss.str());
287294
}
288295
}

src/llm/visual_language_model/legacy/servable_initializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Status VisualLanguageModelLegacyServableInitializer::initialize(std::shared_ptr<
7171
}
7272

7373
try {
74-
properties->pipeline = std::make_shared<ov::genai::VLMPipeline>(parsedModelsPath, properties->device);
74+
properties->pipeline = std::make_shared<ov::genai::VLMPipeline>(parsedModelsPath, properties->device, properties->pluginConfig);
7575
properties->tokenizer = properties->pipeline->get_tokenizer();
7676
} catch (const std::exception& e) {
7777
SPDLOG_ERROR("Error during llm node initialization for models_path: {} exception: {}", parsedModelsPath, e.what());

src/test/http_openai_handler_test.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,35 @@ TEST_F(HttpOpenAIHandlerParsingTest, ParsingMessagesImageLocalFilesystemInvalidP
578578
EXPECT_EQ(apiHandler->parseMessages("/ovms/"), absl::InvalidArgumentError("Image file /ovms/not_exisiting.jpeg parsing failed: can't fopen"));
579579
}
580580

581+
TEST_F(HttpOpenAIHandlerParsingTest, ParsingMessagesImageLocalFilesystemInvalidEscaped) {
582+
std::string json = R"({
583+
"model": "llama",
584+
"messages": [
585+
{
586+
"role": "user",
587+
"content": [
588+
{
589+
"type": "text",
590+
"text": "What is in this image?"
591+
},
592+
{
593+
"type": "image_url",
594+
"image_url": {
595+
"url": ")" + getGenericFullPathForSrcTest("/ovms/src/test/../test/binaryutils/rgb.jpg") +
596+
R"("
597+
}
598+
}
599+
]
600+
}
601+
]
602+
})";
603+
doc.Parse(json.c_str());
604+
ASSERT_FALSE(doc.HasParseError());
605+
std::shared_ptr<ovms::OpenAIChatCompletionsHandler> apiHandler = std::make_shared<ovms::OpenAIChatCompletionsHandler>(doc, ovms::Endpoint::CHAT_COMPLETIONS, std::chrono::system_clock::now(), *tokenizer);
606+
std::string expectedMessage = "Path " + getGenericFullPathForSrcTest("/ovms/src/test/../test/binaryutils/rgb.jpg") + " escape with .. is forbidden.";
607+
EXPECT_EQ(apiHandler->parseMessages("/ovms/"), absl::InvalidArgumentError(expectedMessage.c_str()));
608+
}
609+
581610
TEST_F(HttpOpenAIHandlerParsingTest, ParsingMultipleMessagesSucceeds) {
582611
std::string json = R"({
583612
"model": "llama",

0 commit comments

Comments
 (0)