|
28 | 28 | import org.springframework.ai.model.SpringAIModels;
|
29 | 29 | import org.springframework.ai.model.bedrock.autoconfigure.BedrockAwsConnectionConfiguration;
|
30 | 30 | import org.springframework.ai.model.bedrock.autoconfigure.BedrockAwsConnectionProperties;
|
31 |
| -import org.springframework.beans.factory.annotation.Autowired; |
32 | 31 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
33 | 32 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
34 | 33 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
39 | 38 | import org.springframework.context.annotation.Import;
|
40 | 39 |
|
41 | 40 | /**
|
42 |
| - * {@link AutoConfiguration Auto-configuration} for Bedrock Titan Embedding Model. |
| 41 | + * {@link AutoConfiguration Auto-configuration} for Bedrock Titan Embedding |
| 42 | + * Model. |
43 | 43 | *
|
44 | 44 | * @author Christian Tzolov
|
45 | 45 | * @author Wei Jiang
|
|
48 | 48 | @AutoConfiguration
|
49 | 49 | @ConditionalOnClass(TitanEmbeddingBedrockApi.class)
|
50 | 50 | @EnableConfigurationProperties({ BedrockTitanEmbeddingProperties.class, BedrockAwsConnectionProperties.class })
|
51 |
| -@ConditionalOnProperty(name = SpringAIModelProperties.EMBEDDING_MODEL, havingValue = SpringAIModels.BEDROCK_TITAN, |
52 |
| - matchIfMissing = true) |
| 51 | +@ConditionalOnProperty(name = SpringAIModelProperties.EMBEDDING_MODEL, havingValue = SpringAIModels.BEDROCK_TITAN, matchIfMissing = true) |
53 | 52 | @Import(BedrockAwsConnectionConfiguration.class)
|
54 | 53 | public class BedrockTitanEmbeddingAutoConfiguration {
|
55 | 54 |
|
56 |
| - @Autowired |
57 |
| - private ObservationRegistry observationRegistry; |
58 |
| - |
59 | 55 | @Bean
|
60 | 56 | @ConditionalOnMissingBean
|
61 | 57 | @ConditionalOnBean({ AwsCredentialsProvider.class, AwsRegionProvider.class })
|
62 | 58 | public TitanEmbeddingBedrockApi titanEmbeddingBedrockApi(AwsCredentialsProvider credentialsProvider,
|
63 | 59 | AwsRegionProvider regionProvider, BedrockTitanEmbeddingProperties properties,
|
64 | 60 | BedrockAwsConnectionProperties awsProperties, ObjectMapper objectMapper) {
|
| 61 | + |
| 62 | + // Validate required properties |
| 63 | + if (properties.getModel() == null || awsProperties.getTimeout() == null) { |
| 64 | + throw new IllegalArgumentException("Required properties for TitanEmbeddingBedrockApi are missing."); |
| 65 | + } |
| 66 | + |
65 | 67 | return new TitanEmbeddingBedrockApi(properties.getModel(), credentialsProvider, regionProvider.getRegion(),
|
66 | 68 | objectMapper, awsProperties.getTimeout());
|
67 | 69 | }
|
68 | 70 |
|
| 71 | + @Bean |
| 72 | + @ConditionalOnMissingBean |
| 73 | + public ObservationRegistry observationRegistry() { |
| 74 | + return ObservationRegistry.create(); |
| 75 | + } |
| 76 | + |
69 | 77 | @Bean
|
70 | 78 | @ConditionalOnMissingBean
|
71 | 79 | @ConditionalOnBean(TitanEmbeddingBedrockApi.class)
|
72 | 80 | public BedrockTitanEmbeddingModel titanEmbeddingModel(TitanEmbeddingBedrockApi titanEmbeddingApi,
|
73 |
| - BedrockTitanEmbeddingProperties properties) { |
| 81 | + BedrockTitanEmbeddingProperties properties, ObservationRegistry observationRegistry) { |
| 82 | + |
| 83 | + // Validate required properties |
| 84 | + if (properties.getInputType() == null) { |
| 85 | + throw new IllegalArgumentException("InputType property for BedrockTitanEmbeddingModel is missing."); |
| 86 | + } |
| 87 | + |
74 | 88 | return new BedrockTitanEmbeddingModel(titanEmbeddingApi, observationRegistry)
|
75 |
| - .withInputType(properties.getInputType()); |
| 89 | + .withInputType(properties.getInputType()); |
76 | 90 | }
|
77 | 91 |
|
78 | 92 | }
|
0 commit comments