|
27 | 27 | import static java.util.Collections.singletonList; |
28 | 28 | import static java.util.stream.Collectors.toList; |
29 | 29 | import static org.assertj.core.api.Assertions.assertThat; |
| 30 | +import static org.assertj.core.api.Assertions.assertThatCode; |
30 | 31 | import static org.assertj.core.api.Assertions.within; |
31 | 32 |
|
32 | 33 | import io.opentelemetry.api.common.AttributeKey; |
@@ -667,6 +668,65 @@ void testConverseToolCall() { |
667 | 668 | + "The current weather in Seattle is 50 degrees and raining. In San Francisco, the weather is 70 degrees and sunny."))))); |
668 | 669 | } |
669 | 670 |
|
| 671 | + @Test |
| 672 | + void testConverseStreamToolCallWithEmptyToolArguments() { |
| 673 | + BedrockRuntimeAsyncClientBuilder builder = BedrockRuntimeAsyncClient.builder(); |
| 674 | + builder.overrideConfiguration(createOverrideConfigurationBuilder().build()); |
| 675 | + configureClient(builder); |
| 676 | + BedrockRuntimeAsyncClient client = configureBedrockRuntimeClient(builder.build()); |
| 677 | + |
| 678 | + String modelId = "amazon.nova-micro-v1:0"; |
| 679 | + List<Message> messages = new ArrayList<>(); |
| 680 | + messages.add( |
| 681 | + Message.builder() |
| 682 | + .role(ConversationRole.USER) |
| 683 | + .content(ContentBlock.fromText("What time is it?")) |
| 684 | + .build()); |
| 685 | + |
| 686 | + ConverseStreamResponseHandler responseHandler = |
| 687 | + ConverseStreamResponseHandler.builder() |
| 688 | + .subscriber(ConverseStreamResponseHandler.Visitor.builder().build()) |
| 689 | + .build(); |
| 690 | + |
| 691 | + assertThatCode( |
| 692 | + () -> |
| 693 | + client |
| 694 | + .converseStream( |
| 695 | + ConverseStreamRequest.builder() |
| 696 | + .modelId(modelId) |
| 697 | + .messages(messages) |
| 698 | + .toolConfig(serverTimeToolConfig()) |
| 699 | + .build(), |
| 700 | + responseHandler) |
| 701 | + .join()) |
| 702 | + .doesNotThrowAnyException(); |
| 703 | + |
| 704 | + getTesting() |
| 705 | + .waitAndAssertLogRecords( |
| 706 | + log -> |
| 707 | + log.hasAttributesSatisfyingExactly( |
| 708 | + equalTo(GEN_AI_PROVIDER_NAME, AWS_BEDROCK), |
| 709 | + equalTo(EVENT_NAME, "gen_ai.user.message")) |
| 710 | + .hasBody(Value.of(KeyValue.of("content", Value.of("What time is it?")))), |
| 711 | + log -> |
| 712 | + log.hasAttributesSatisfyingExactly( |
| 713 | + equalTo(GEN_AI_PROVIDER_NAME, AWS_BEDROCK), |
| 714 | + equalTo(EVENT_NAME, "gen_ai.choice")) |
| 715 | + .hasBody( |
| 716 | + Value.of( |
| 717 | + KeyValue.of("finish_reason", Value.of("tool_use")), |
| 718 | + KeyValue.of("index", Value.of(0)), |
| 719 | + KeyValue.of( |
| 720 | + "toolCalls", |
| 721 | + Value.of( |
| 722 | + Value.of( |
| 723 | + KeyValue.of("name", Value.of("get_server_time")), |
| 724 | + KeyValue.of("arguments", Value.of("{}")), |
| 725 | + KeyValue.of("id", Value.of("tooluse_empty_params_test")), |
| 726 | + KeyValue.of("type", Value.of("function"))))), |
| 727 | + KeyValue.of("content", Value.of(""))))); |
| 728 | + } |
| 729 | + |
670 | 730 | @Test |
671 | 731 | void testConverseToolCallStream() { |
672 | 732 | BedrockRuntimeAsyncClientBuilder builder = BedrockRuntimeAsyncClient.builder(); |
@@ -1067,6 +1127,27 @@ void testConverseToolCallStream() { |
1067 | 1127 | + "The current weather in Seattle is 50 degrees and it is raining. In San Francisco, the weather is 70 degrees and sunny."))))); |
1068 | 1128 | } |
1069 | 1129 |
|
| 1130 | + private static ToolConfiguration serverTimeToolConfig() { |
| 1131 | + return ToolConfiguration.builder() |
| 1132 | + .tools( |
| 1133 | + Tool.builder() |
| 1134 | + .toolSpec( |
| 1135 | + ToolSpecification.builder() |
| 1136 | + .name("get_server_time") |
| 1137 | + .description("Get the current server time.") |
| 1138 | + .inputSchema( |
| 1139 | + ToolInputSchema.builder() |
| 1140 | + .json( |
| 1141 | + Document.mapBuilder() |
| 1142 | + .putString("type", "object") |
| 1143 | + .putDocument("properties", Document.mapBuilder().build()) |
| 1144 | + .build()) |
| 1145 | + .build()) |
| 1146 | + .build()) |
| 1147 | + .build()) |
| 1148 | + .build(); |
| 1149 | + } |
| 1150 | + |
1070 | 1151 | private static ToolConfiguration currentWeatherToolConfig() { |
1071 | 1152 | return ToolConfiguration.builder() |
1072 | 1153 | .tools( |
|
0 commit comments