Skip to content

Commit

Permalink
Merge pull request #221 from jmartisk/provider-selection
Browse files Browse the repository at this point in the history
Fail if selected chat/embedding model isn't the one found on classpath
  • Loading branch information
cescoffier authored Jan 14, 2024
2 parents d98578e + 2d3a71c commit e6c425b
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ private <T extends ProviderHolder> 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
Expand Down Expand Up @@ -170,10 +176,16 @@ private <T extends ProviderHolder> 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
Expand Down

0 comments on commit e6c425b

Please sign in to comment.