@@ -85,11 +85,13 @@ std::string GraphExport::getDraftModelDirectoryPath(const std::string& directory
8585
8686static Status createTextGenerationGraphTemplate (const std::string& directoryPath, const HFSettingsImpl& hfSettings) {
8787 if (!std::holds_alternative<TextGenGraphSettingsImpl>(hfSettings.graphSettings )) {
88+ SPDLOG_ERROR (" Graph options not initialized for text generation." );
8889 return StatusCode::INTERNAL_ERROR;
8990 }
9091 auto & graphSettings = std::get<TextGenGraphSettingsImpl>(hfSettings.graphSettings );
9192 auto & ggufFilename = hfSettings.ggufFilename ;
9293 auto & exportSettings = hfSettings.exportSettings ;
94+
9395 std::ostringstream oss;
9496 oss << OVMS_VERSION_GRAPH_LINE;
9597 std::string modelsPath = constructModelsPath (graphSettings.modelPath , ggufFilename);
@@ -188,13 +190,25 @@ static Status createTextGenerationGraphTemplate(const std::string& directoryPath
188190 return FileSystem::createFileOverwrite (fullPath, oss.str ());
189191}
190192
191- static Status createRerankGraphTemplate (const std::string& directoryPath, const RerankGraphSettingsImpl& graphSettings) {
193+ static Status createRerankGraphTemplate (const std::string& directoryPath, const HFSettingsImpl& hfSettings) {
194+ if (!std::holds_alternative<RerankGraphSettingsImpl>(hfSettings.graphSettings )) {
195+ SPDLOG_ERROR (" Graph options not initialized for reranking." );
196+ return StatusCode::INTERNAL_ERROR;
197+ }
198+ auto & graphSettings = std::get<RerankGraphSettingsImpl>(hfSettings.graphSettings );
199+ auto & ggufFilename = hfSettings.ggufFilename ;
200+ auto & exportSettings = hfSettings.exportSettings ;
201+
192202 std::ostringstream oss;
193203 oss << OVMS_VERSION_GRAPH_LINE;
194204 // Windows path creation - graph parser needs forward slashes in paths
195- std::string graphOkPath = graphSettings.modelPath ;
196- if (FileSystem::getOsSeparator () != " /" ) {
197- std::replace (graphOkPath.begin (), graphOkPath.end (), ' \\ ' , ' /' );
205+ std::string modelsPath = constructModelsPath (graphSettings.modelPath , ggufFilename);
206+ SPDLOG_TRACE (" modelsPath: {}, directoryPath: {}, ggufFilename: {}" , modelsPath, directoryPath, ggufFilename.value_or (" std::nullopt" ));
207+ auto pluginConfigOrStatus = GraphExport::createPluginString (graphSettings.pluginConfig , exportSettings);
208+ if (std::holds_alternative<Status>(pluginConfigOrStatus)) {
209+ auto status = std::get<Status>(pluginConfigOrStatus);
210+ SPDLOG_ERROR (" Failed to create plugin config: {}" , status.string ());
211+ return status;
198212 }
199213 // clang-format off
200214 oss << R"(
@@ -210,11 +224,11 @@ node {
210224 node_options: {
211225 [type.googleapis.com / mediapipe.RerankCalculatorOVOptions]: {
212226 models_path: ")"
213- << graphOkPath << R"( ",
227+ << modelsPath << R"( ",
214228 max_allowed_chunks: )"
215229 << graphSettings.maxAllowedChunks << R"( ,
216230 target_device: ")" << graphSettings.targetDevice << R"( ",
217- plugin_config: '{ "NUM_STREAMS": " )" << graphSettings. numStreams << R"( "} ',
231+ plugin_config: ')" << std::get<std::string>(pluginConfigOrStatus) << R"( ',
218232 }
219233 }
220234})" ;
@@ -232,15 +246,25 @@ node {
232246 return FileSystem::createFileOverwrite (fullPath, oss.str ());
233247}
234248
235- static Status createEmbeddingsGraphTemplate (const std::string& directoryPath, const EmbeddingsGraphSettingsImpl& graphSettings) {
249+ static Status createEmbeddingsGraphTemplate (const std::string& directoryPath, const HFSettingsImpl& hfSettings) {
250+ if (!std::holds_alternative<EmbeddingsGraphSettingsImpl>(hfSettings.graphSettings )) {
251+ SPDLOG_ERROR (" Graph options not initialized for embeddings." );
252+ return StatusCode::INTERNAL_ERROR;
253+ }
254+ auto & graphSettings = std::get<EmbeddingsGraphSettingsImpl>(hfSettings.graphSettings );
255+ auto & ggufFilename = hfSettings.ggufFilename ;
256+ auto & exportSettings = hfSettings.exportSettings ;
257+
236258 std::ostringstream oss;
237259 oss << OVMS_VERSION_GRAPH_LINE;
238- // Windows path creation - graph parser needs forward slashes in paths
239- std::string graphOkPath = graphSettings.modelPath ;
240- if (FileSystem::getOsSeparator () != " /" ) {
241- std::replace (graphOkPath.begin (), graphOkPath.end (), ' \\ ' , ' /' );
260+ std::string modelsPath = constructModelsPath (graphSettings.modelPath , ggufFilename);
261+ SPDLOG_TRACE (" modelsPath: {}, directoryPath: {}, ggufFilename: {}" , modelsPath, directoryPath, ggufFilename.value_or (" std::nullopt" ));
262+ auto pluginConfigOrStatus = GraphExport::createPluginString (graphSettings.pluginConfig , exportSettings);
263+ if (std::holds_alternative<Status>(pluginConfigOrStatus)) {
264+ auto status = std::get<Status>(pluginConfigOrStatus);
265+ SPDLOG_ERROR (" Failed to create plugin config: {}" , status.string ());
266+ return status;
242267 }
243-
244268 // clang-format off
245269 oss << R"(
246270input_stream: "REQUEST_PAYLOAD:input"
@@ -255,15 +279,15 @@ node {
255279 node_options: {
256280 [type.googleapis.com / mediapipe.EmbeddingsCalculatorOVOptions]: {
257281 models_path: ")"
258- << graphOkPath << R"( ",
282+ << modelsPath << R"( ",
259283 normalize_embeddings: )"
260284 << graphSettings.normalize << R"( ,
261285 truncate: )"
262286 << graphSettings.truncate << R"( ,
263287 pooling: )"
264288 << graphSettings.pooling << R"( ,
265289 target_device: ")" << graphSettings.targetDevice << R"( ",
266- plugin_config: '{ "NUM_STREAMS": " )" << graphSettings. numStreams << R"( "} ',
290+ plugin_config: ')" << std::get<std::string>(pluginConfigOrStatus) << R"( ',
267291 }
268292 }
269293})" ;
@@ -281,7 +305,24 @@ node {
281305 return FileSystem::createFileOverwrite (fullPath, oss.str ());
282306}
283307
284- static Status createImageGenerationGraphTemplate (const std::string& directoryPath, const ImageGenerationGraphSettingsImpl& graphSettings) {
308+ static Status createImageGenerationGraphTemplate (const std::string& directoryPath, const HFSettingsImpl& hfSettings) {
309+ if (!std::holds_alternative<ImageGenerationGraphSettingsImpl>(hfSettings.graphSettings )) {
310+ SPDLOG_ERROR (" Graph options not initialized for image generation." );
311+ return StatusCode::INTERNAL_ERROR;
312+ }
313+ auto & graphSettings = std::get<ImageGenerationGraphSettingsImpl>(hfSettings.graphSettings );
314+ auto & exportSettings = hfSettings.exportSettings ;
315+ auto & ggufFilename = hfSettings.ggufFilename ;
316+ std::string modelsPath = constructModelsPath (graphSettings.modelPath , ggufFilename);
317+ SPDLOG_TRACE (" modelsPath: {}, directoryPath: {}, ggufFilename: {}" , modelsPath, directoryPath, ggufFilename.value_or (" std::nullopt" ));
318+ auto pluginConfigOrStatus = GraphExport::createPluginString (graphSettings.pluginConfig , exportSettings);
319+ if (std::holds_alternative<Status>(pluginConfigOrStatus)) {
320+ auto status = std::get<Status>(pluginConfigOrStatus);
321+ SPDLOG_ERROR (" Failed to create plugin config: {}" , status.string ());
322+ return status;
323+ }
324+ const std::string pluginConfig = std::get<std::string>(pluginConfigOrStatus);
325+
285326 std::ostringstream oss;
286327 oss << OVMS_VERSION_GRAPH_LINE;
287328 // clang-format off
@@ -299,10 +340,10 @@ node: {
299340 [type.googleapis.com / mediapipe.ImageGenCalculatorOptions]: {
300341 models_path: ")" << graphSettings.modelPath << R"( "
301342 device: ")" << graphSettings.targetDevice << R"( ")" ;
302-
303- if (graphSettings. pluginConfig .size ()) {
343+ // TODO by default our utility generates empty plugin config which may differ in behavior to nto setting it at all
344+ if (pluginConfig.size () > 4 ) {
304345 oss << R"(
305- plugin_config: ')" << graphSettings. pluginConfig << R"( ')" ;
346+ plugin_config: ')" << std::get<std::string>(pluginConfigOrStatus) << R"( ')" ;
306347 }
307348
308349 if (graphSettings.resolution .size ()) {
@@ -383,26 +424,11 @@ Status GraphExport::createServableConfig(const std::string& directoryPath, const
383424 if (hfSettings.task == TEXT_GENERATION_GRAPH) {
384425 return createTextGenerationGraphTemplate (directoryPath, hfSettings);
385426 } else if (hfSettings.task == EMBEDDINGS_GRAPH) {
386- if (std::holds_alternative<EmbeddingsGraphSettingsImpl>(hfSettings.graphSettings )) {
387- return createEmbeddingsGraphTemplate (directoryPath, std::get<EmbeddingsGraphSettingsImpl>(hfSettings.graphSettings ));
388- } else {
389- SPDLOG_ERROR (" Graph options not initialized for embeddings." );
390- return StatusCode::INTERNAL_ERROR;
391- }
427+ return createEmbeddingsGraphTemplate (directoryPath, hfSettings);
392428 } else if (hfSettings.task == RERANK_GRAPH) {
393- if (std::holds_alternative<RerankGraphSettingsImpl>(hfSettings.graphSettings )) {
394- return createRerankGraphTemplate (directoryPath, std::get<RerankGraphSettingsImpl>(hfSettings.graphSettings ));
395- } else {
396- SPDLOG_ERROR (" Graph options not initialized for rerank." );
397- return StatusCode::INTERNAL_ERROR;
398- }
429+ return createRerankGraphTemplate (directoryPath, hfSettings);
399430 } else if (hfSettings.task == IMAGE_GENERATION_GRAPH) {
400- if (std::holds_alternative<ImageGenerationGraphSettingsImpl>(hfSettings.graphSettings )) {
401- return createImageGenerationGraphTemplate (directoryPath, std::get<ImageGenerationGraphSettingsImpl>(hfSettings.graphSettings ));
402- } else {
403- SPDLOG_ERROR (" Graph options not initialized for image generation." );
404- return StatusCode::INTERNAL_ERROR;
405- }
431+ return createImageGenerationGraphTemplate (directoryPath, hfSettings);
406432 } else if (hfSettings.task == UNKNOWN_GRAPH) {
407433 SPDLOG_ERROR (" Graph options not initialized." );
408434 return StatusCode::INTERNAL_ERROR;
0 commit comments