From 2d3a71cdacf6d56a2c58b188cb7a9cfb57cbab37 Mon Sep 17 00:00:00 2001 From: Jan Martiska Date: Fri, 12 Jan 2024 11:46:28 +0100 Subject: [PATCH] Fail if selected chat/embedding model isn't the one found on classpath --- .../langchain4j/deployment/BeansProcessor.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/BeansProcessor.java b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/BeansProcessor.java index a765720d7..52b053887 100644 --- a/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/BeansProcessor.java +++ b/core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/BeansProcessor.java @@ -139,6 +139,12 @@ private String selectProvider( requestedBeanName)); } if (availableProviders.size() == 1) { + // user has selected a provider, but it's not the one that is available + if (userSelectedProvider.isPresent() && !availableProviders.get(0).equals(userSelectedProvider.get())) { + throw new ConfigurationException(String.format( + "A %s bean with provider=%s was requested was requested via configuration, but the only provider found on the classpath is %s.", + requestedBeanName, userSelectedProvider.get(), availableProviders.get(0))); + } return availableProviders.get(0); } // multiple providers exist, so we now need the configuration to select the proper one @@ -170,10 +176,16 @@ private String selectEmbeddingModelProvider( throw new ConfigurationException(String.format( "A %s bean was requested, but no langchain4j providers were configured and no in-process embedding model were found on the classpath. " + - "Consider adding an extension like 'quarkus-langchain4j-openai' or one of the in-process embedding model.", + "Consider adding an extension like 'quarkus-langchain4j-openai' or one of the in-process embedding models.", requestedBeanName)); } if (availableProviders.size() == 1) { + // user has selected a provider, but it's not the one that is available + if (userSelectedProvider.isPresent() && !availableProviders.get(0).equals(userSelectedProvider.get())) { + throw new ConfigurationException(String.format( + "Embedding model provider %s was requested via configuration, but the only provider found on the classpath is %s.", + userSelectedProvider.get(), availableProviders.get(0))); + } return availableProviders.get(0); } // multiple providers exist, so we now need the configuration to select the proper one