Skip to content

Commit 6f1f926

Browse files
committed
added cohere support :: resolved checkstyle violations
Signed-off-by: Ricken Bazolo <ricken.bazolo@gmail.com>
1 parent 578155e commit 6f1f926

34 files changed

+539
-376
lines changed

auto-configurations/models/spring-ai-autoconfigure-model-cohere/pom.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@
2424

2525
<dependencies>
2626

27-
<!-- Spring AI dependencies -->
28-
2927
<dependency>
3028
<groupId>org.springframework.ai</groupId>
3129
<artifactId>spring-ai-cohere</artifactId>
3230
<version>${project.parent.version}</version>
3331
<optional>true</optional>
3432
</dependency>
3533

36-
<!-- Spring AI auto configurations -->
37-
3834
<dependency>
3935
<groupId>org.springframework.ai</groupId>
4036
<artifactId>spring-ai-autoconfigure-model-tool</artifactId>
@@ -53,13 +49,23 @@
5349
<version>${project.parent.version}</version>
5450
</dependency>
5551

56-
<!-- Boot dependencies -->
5752
<dependency>
5853
<groupId>org.springframework.boot</groupId>
5954
<artifactId>spring-boot-starter</artifactId>
6055
<optional>true</optional>
6156
</dependency>
6257

58+
<dependency>
59+
<groupId>org.springframework.boot</groupId>
60+
<artifactId>spring-boot-starter-webclient</artifactId>
61+
<optional>true</optional>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-restclient</artifactId>
66+
<optional>true</optional>
67+
</dependency>
68+
6369
<dependency>
6470
<groupId>org.springframework.boot</groupId>
6571
<artifactId>spring-boot-configuration-processor</artifactId>

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/main/java/org/springframework/ai/cohere/autoconfigure/CohereChatAutoConfiguration.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

319
import io.micrometer.observation.ObservationRegistry;
20+
421
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
522
import org.springframework.ai.cohere.api.CohereApi;
623
import org.springframework.ai.cohere.chat.CohereChatModel;
@@ -17,10 +34,11 @@
1734
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1835
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
1936
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
20-
import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
2137
import org.springframework.boot.context.properties.EnableConfigurationProperties;
38+
import org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration;
39+
import org.springframework.boot.webclient.autoconfigure.WebClientAutoConfiguration;
2240
import org.springframework.context.annotation.Bean;
23-
import org.springframework.retry.support.RetryTemplate;
41+
import org.springframework.core.retry.RetryTemplate;
2442
import org.springframework.util.Assert;
2543
import org.springframework.util.StringUtils;
2644
import org.springframework.web.client.ResponseErrorHandler;
@@ -32,8 +50,8 @@
3250
*
3351
* @author Ricken Bazolo
3452
*/
35-
@AutoConfiguration(after = { RestClientAutoConfiguration.class, SpringAiRetryAutoConfiguration.class,
36-
ToolCallingAutoConfiguration.class })
53+
@AutoConfiguration(after = { RestClientAutoConfiguration.class, WebClientAutoConfiguration.class,
54+
SpringAiRetryAutoConfiguration.class, ToolCallingAutoConfiguration.class })
3755
@EnableConfigurationProperties({ CohereCommonProperties.class, CohereChatProperties.class })
3856
@ConditionalOnProperty(name = SpringAIModelProperties.CHAT_MODEL, havingValue = SpringAIModels.COHERE,
3957
matchIfMissing = true)
@@ -61,7 +79,7 @@ public CohereChatModel chereChatModel(CohereCommonProperties commonProperties, C
6179
.toolCallingManager(toolCallingManager)
6280
.toolExecutionEligibilityPredicate(
6381
cohereToolExecutionEligibilityPredicate.getIfUnique(DefaultToolExecutionEligibilityPredicate::new))
64-
.retryTemplate(retryTemplate)
82+
.retryTemplate(new RetryTemplate())
6583
.observationRegistry(observationRegistry.getIfUnique(() -> ObservationRegistry.NOOP))
6684
.build();
6785

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/main/java/org/springframework/ai/cohere/autoconfigure/CohereChatProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

319
import org.springframework.ai.cohere.api.CohereApi;

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/main/java/org/springframework/ai/cohere/autoconfigure/CohereCommonProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

319
import org.springframework.boot.context.properties.ConfigurationProperties;

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/main/java/org/springframework/ai/cohere/autoconfigure/CohereEmbeddingAutoConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.ai.cohere.autoconfigure;
1818

1919
import io.micrometer.observation.ObservationRegistry;
20+
2021
import org.springframework.ai.cohere.api.CohereApi;
2122
import org.springframework.ai.cohere.embedding.CohereEmbeddingModel;
2223
import org.springframework.ai.embedding.observation.EmbeddingModelObservationConvention;
@@ -28,10 +29,10 @@
2829
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2930
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3031
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
31-
import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
3232
import org.springframework.boot.context.properties.EnableConfigurationProperties;
33+
import org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration;
3334
import org.springframework.context.annotation.Bean;
34-
import org.springframework.retry.support.RetryTemplate;
35+
import org.springframework.core.retry.RetryTemplate;
3536
import org.springframework.util.Assert;
3637
import org.springframework.util.StringUtils;
3738
import org.springframework.web.client.ResponseErrorHandler;

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/main/java/org/springframework/ai/cohere/autoconfigure/CohereEmbeddingProperties.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717
package org.springframework.ai.cohere.autoconfigure;
1818

19-
import org.springframework.ai.cohere.api.CohereApi;
20-
import org.springframework.ai.cohere.api.CohereApi.EmbeddingType;
19+
import java.util.List;
20+
2121
import org.springframework.ai.cohere.api.CohereApi.EmbeddingModel;
22+
import org.springframework.ai.cohere.api.CohereApi.EmbeddingType;
2223
import org.springframework.ai.cohere.embedding.CohereEmbeddingOptions;
2324
import org.springframework.ai.document.MetadataMode;
2425
import org.springframework.boot.context.properties.ConfigurationProperties;
2526
import org.springframework.boot.context.properties.NestedConfigurationProperty;
2627

27-
import java.util.List;
28-
2928
/**
3029
* Configuration properties for Cohere embedding model.
3130
*

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/main/java/org/springframework/ai/cohere/autoconfigure/CohereParentProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

319
/**

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/test/java/org/springframework/ai/cohere/autoconfigure/CohereAutoConfigurationIT.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

19+
import java.util.List;
20+
321
import org.apache.commons.logging.Log;
422
import org.apache.commons.logging.LogFactory;
523
import org.junit.jupiter.api.Test;
624
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
25+
import reactor.core.publisher.Flux;
26+
727
import org.springframework.ai.cohere.chat.CohereChatModel;
828
import org.springframework.ai.cohere.embedding.CohereEmbeddingModel;
929
import org.springframework.ai.embedding.EmbeddingResponse;
1030
import org.springframework.ai.utils.SpringAiTestAutoConfigurations;
1131
import org.springframework.boot.autoconfigure.AutoConfigurations;
1232
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
1333

14-
import java.util.List;
15-
1634
import static org.assertj.core.api.Assertions.assertThat;
1735

1836
/**
@@ -55,4 +73,23 @@ void embedding() {
5573
});
5674
}
5775

76+
@Test
77+
void generateStreaming() {
78+
this.contextRunner.withConfiguration(SpringAiTestAutoConfigurations.of(CohereChatAutoConfiguration.class))
79+
.run(context -> {
80+
CohereChatModel chatModel = context.getBean(CohereChatModel.class);
81+
Flux<org.springframework.ai.chat.model.ChatResponse> responseFlux = chatModel
82+
.stream(new org.springframework.ai.chat.prompt.Prompt(
83+
new org.springframework.ai.chat.messages.UserMessage("Hello")));
84+
String response = responseFlux.collectList()
85+
.block()
86+
.stream()
87+
.map(chatResponse -> chatResponse.getResults().get(0).getOutput().getText())
88+
.collect(java.util.stream.Collectors.joining());
89+
90+
assertThat(response).isNotEmpty();
91+
logger.info("Response: " + response);
92+
});
93+
}
94+
5895
}

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/test/java/org/springframework/ai/cohere/autoconfigure/CohereModelConfigurationTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

319
import org.junit.jupiter.api.Test;
20+
421
import org.springframework.ai.cohere.chat.CohereChatModel;
522
import org.springframework.ai.cohere.embedding.CohereEmbeddingModel;
623
import org.springframework.ai.utils.SpringAiTestAutoConfigurations;

auto-configurations/models/spring-ai-autoconfigure-model-cohere/src/test/java/org/springframework/ai/cohere/autoconfigure/CoherePropertiesTests.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
/*
2+
* Copyright 2023-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.ai.cohere.autoconfigure;
218

319
import org.junit.jupiter.api.Test;
20+
421
import org.springframework.ai.cohere.api.CohereApi;
522
import org.springframework.ai.retry.autoconfigure.SpringAiRetryAutoConfiguration;
623
import org.springframework.ai.utils.SpringAiTestAutoConfigurations;
724
import org.springframework.boot.autoconfigure.AutoConfigurations;
8-
import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration;
25+
import org.springframework.boot.restclient.autoconfigure.RestClientAutoConfiguration;
926
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
1027

1128
import static org.assertj.core.api.Assertions.assertThat;

0 commit comments

Comments
 (0)