Skip to content

Commit d5bbb13

Browse files
committed
feat(bedrock): add tests for tool annotation and supplier-based tool calling
Add integration tests for BedrockNovaChatClient that verify: - Tool annotation for method without input arguments. - Supplier-based tool calling implementation. Related to #1878 Signed-off-by: Christian Tzolov <[email protected]>
1 parent 972eb49 commit d5bbb13

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

models/spring-ai-bedrock-converse/src/test/java/org/springframework/ai/bedrock/converse/client/BedrockNovaChatClientIT.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.time.Duration;
2121
import java.util.Set;
22+
import java.util.function.Supplier;
2223

2324
import org.junit.jupiter.api.Test;
2425
import org.slf4j.Logger;
@@ -32,6 +33,7 @@
3233
import org.springframework.ai.chat.model.ChatModel;
3334
import org.springframework.ai.content.Media;
3435
import org.springframework.ai.model.tool.ToolCallingChatOptions;
36+
import org.springframework.ai.tool.annotation.Tool;
3537
import org.springframework.ai.tool.function.FunctionToolCallback;
3638
import org.springframework.beans.factory.annotation.Autowired;
3739
import org.springframework.boot.SpringBootConfiguration;
@@ -171,6 +173,61 @@ public record WeatherRequest(String location, String unit) {
171173
public record WeatherResponse(int temp, String unit) {
172174
}
173175

176+
// https://github.com/spring-projects/spring-ai/issues/1878
177+
@Test
178+
void toolAnnotationWeatherForecastTest() {
179+
180+
ChatClient chatClient = ChatClient.builder(this.chatModel).build();
181+
182+
String response = chatClient.prompt()
183+
.tools(new DummyWeatherForcastTools())
184+
.user("Get current weather in Amsterdam")
185+
.call()
186+
.content();
187+
188+
assertThat(response).isNotEmpty();
189+
assertThat(response).contains("20 degrees");
190+
}
191+
192+
public static class DummyWeatherForcastTools {
193+
194+
@Tool(description = "Get the current weather forcast in Amsterdam")
195+
String getCurrentDateTime() {
196+
return "Weahter is hot and sunny wiht a temperature of 20 degrees";
197+
}
198+
199+
}
200+
201+
// https://github.com/spring-projects/spring-ai/issues/1878
202+
@Test
203+
void supplierBasedToolCalling() {
204+
205+
ChatClient chatClient = ChatClient.builder(this.chatModel).build();
206+
207+
WeatherService.Response response = chatClient.prompt()
208+
.toolCallbacks(FunctionToolCallback.builder("weather", new WeatherService())
209+
.description("Get the current weather")
210+
.inputType(Void.class)
211+
.build())
212+
.user("Get current weather in Amsterdam")
213+
.call()
214+
.entity(WeatherService.Response.class);
215+
216+
assertThat(response).isNotNull();
217+
assertThat(response.temp()).isEqualTo(30.0);
218+
}
219+
220+
public static class WeatherService implements Supplier<WeatherService.Response> {
221+
222+
public record Response(double temp) {
223+
}
224+
225+
public Response get() {
226+
return new Response(30.0);
227+
}
228+
229+
}
230+
174231
@SpringBootConfiguration
175232
public static class Config {
176233

0 commit comments

Comments
 (0)