Description:
There are three bean factory methods for beans that cover the same role in the project. However, they use different annotations, resulting in inconsistent behavior. The methods are as follows:
-
AzureOpenAiChatModel
:java @Bean @ConditionalOnProperty(prefix = AzureOpenAiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) public AzureOpenAiChatModel(...) { // Implementation }
-
OpenAiChatModel
:java @Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = OpenAiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) public OpenAiChatModel(...) { // Implementation }
-
VertexAiGeminiChatModel
:java @Bean @ConditionalOnMissingBean public VertexAiGeminiChatModel(...) { // Implementation }
Problem:
- The
AzureOpenAiChatModel
method does not have the@ConditionalOnMissingBean
annotation. - The
VertexAiGeminiChatModel
method is missing both@ConditionalOnProperty
and the prefix configuration properties. - This inconsistency can lead to unpredictable behavior and makes it harder to customize the bean configurations.
Expected Behavior:
All bean factory methods should follow a consistent pattern to ensure predictable behavior and allow for better customization. The pattern used by the OpenAiChatModel
method is more flexible and should be adopted for all three methods.
Suggested Solution:
Update the annotations on AzureOpenAiChatModel
and VertexAiGeminiChatModel
methods to match the pattern used by OpenAiChatModel
. Here is the suggested modification:
-
For
AzureOpenAiChatModel
:java @Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = AzureOpenAiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) public AzureOpenAiChatModel(...) { // Implementation }
-
For
VertexAiGeminiChatModel
:java @Bean @ConditionalOnMissingBean @ConditionalOnProperty(prefix = VertexAiGeminiChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) public VertexAiGeminiChatModel(...) { // Implementation }
Additional Information:
- This change will ensure that all three beans are only created if no other bean of the same type exists (
@ConditionalOnMissingBean
) and if their respective properties are enabled (@ConditionalOnProperty
). - The configuration prefixes should be consistent with the properties used in the respective configuration classes.
Comment From: markpollack
Thanks for reporting this!