|
| 1 | +package ai.koog.integration.tests.executor |
| 2 | + |
| 3 | +import ai.koog.integration.tests.utils.MediaTestScenarios.AudioTestScenario |
| 4 | +import ai.koog.integration.tests.utils.MediaTestScenarios.ImageTestScenario |
| 5 | +import ai.koog.integration.tests.utils.MediaTestScenarios.MarkdownTestScenario |
| 6 | +import ai.koog.integration.tests.utils.MediaTestScenarios.TextTestScenario |
| 7 | +import ai.koog.integration.tests.utils.Models |
| 8 | +import ai.koog.integration.tests.utils.TestCredentials.readAwsAccessKeyIdFromEnv |
| 9 | +import ai.koog.integration.tests.utils.TestCredentials.readAwsBedrockGuardrailIdFromEnv |
| 10 | +import ai.koog.integration.tests.utils.TestCredentials.readAwsBedrockGuardrailVersionFromEnv |
| 11 | +import ai.koog.integration.tests.utils.TestCredentials.readAwsSecretAccessKeyFromEnv |
| 12 | +import ai.koog.integration.tests.utils.TestCredentials.readAwsSessionTokenFromEnv |
| 13 | +import ai.koog.prompt.executor.clients.LLMClient |
| 14 | +import ai.koog.prompt.executor.clients.bedrock.BedrockAPIMethod |
| 15 | +import ai.koog.prompt.executor.clients.bedrock.BedrockClientSettings |
| 16 | +import ai.koog.prompt.executor.clients.bedrock.BedrockGuardrailsSettings |
| 17 | +import ai.koog.prompt.executor.clients.bedrock.BedrockLLMClient |
| 18 | +import ai.koog.prompt.executor.clients.bedrock.BedrockModels |
| 19 | +import ai.koog.prompt.executor.clients.bedrock.converse.BedrockConverseParams |
| 20 | +import ai.koog.prompt.executor.llms.MultiLLMPromptExecutor |
| 21 | +import ai.koog.prompt.executor.model.PromptExecutor |
| 22 | +import ai.koog.prompt.llm.LLMProvider |
| 23 | +import ai.koog.prompt.llm.LLModel |
| 24 | +import ai.koog.prompt.params.LLMParams |
| 25 | +import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider |
| 26 | +import kotlinx.serialization.json.buildJsonObject |
| 27 | +import kotlinx.serialization.json.put |
| 28 | +import org.junit.jupiter.api.Disabled |
| 29 | +import org.junit.jupiter.params.ParameterizedTest |
| 30 | +import org.junit.jupiter.params.provider.Arguments |
| 31 | +import org.junit.jupiter.params.provider.MethodSource |
| 32 | +import java.util.stream.Stream |
| 33 | +import kotlin.enums.EnumEntries |
| 34 | + |
| 35 | +/** |
| 36 | + * Test newer Bedrock Converse API using the same suite of executor tests. |
| 37 | + */ |
| 38 | +class BedrockConverseApiIntegrationTest : ExecutorIntegrationTestBase() { |
| 39 | + companion object { |
| 40 | + private fun EnumEntries<*>.combineBedrockModels(): Stream<Arguments> { |
| 41 | + return toList() |
| 42 | + .flatMap { scenario -> |
| 43 | + Models |
| 44 | + .bedrockModels() |
| 45 | + .toArray() |
| 46 | + .map { model -> Arguments.of(scenario, model) } |
| 47 | + } |
| 48 | + .stream() |
| 49 | + } |
| 50 | + |
| 51 | + @JvmStatic |
| 52 | + fun markdownScenarioModelCombinations(): Stream<Arguments> { |
| 53 | + return MarkdownTestScenario.entries.combineBedrockModels() |
| 54 | + } |
| 55 | + |
| 56 | + @JvmStatic |
| 57 | + fun imageScenarioModelCombinations(): Stream<Arguments> { |
| 58 | + return ImageTestScenario.entries.combineBedrockModels() |
| 59 | + } |
| 60 | + |
| 61 | + @JvmStatic |
| 62 | + fun textScenarioModelCombinations(): Stream<Arguments> { |
| 63 | + return TextTestScenario.entries.combineBedrockModels() |
| 64 | + } |
| 65 | + |
| 66 | + @JvmStatic |
| 67 | + fun audioScenarioModelCombinations(): Stream<Arguments> { |
| 68 | + return AudioTestScenario.entries.combineBedrockModels() |
| 69 | + } |
| 70 | + |
| 71 | + @JvmStatic |
| 72 | + fun reasoningCapableModels(): Stream<LLModel> { |
| 73 | + return listOf(BedrockModels.AnthropicClaude4_5Sonnet).stream() |
| 74 | + } |
| 75 | + |
| 76 | + @JvmStatic |
| 77 | + fun allCompletionModels(): Stream<LLModel> { |
| 78 | + return Models.bedrockModels() |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + private val client = run { |
| 83 | + BedrockLLMClient( |
| 84 | + identityProvider = StaticCredentialsProvider { |
| 85 | + this.accessKeyId = readAwsAccessKeyIdFromEnv() |
| 86 | + this.secretAccessKey = readAwsSecretAccessKeyFromEnv() |
| 87 | + readAwsSessionTokenFromEnv()?.let { this.sessionToken = it } |
| 88 | + }, |
| 89 | + settings = BedrockClientSettings( |
| 90 | + moderationGuardrailsSettings = BedrockGuardrailsSettings( |
| 91 | + guardrailIdentifier = readAwsBedrockGuardrailIdFromEnv(), |
| 92 | + guardrailVersion = readAwsBedrockGuardrailVersionFromEnv() |
| 93 | + ), |
| 94 | + apiMethod = BedrockAPIMethod.Converse, |
| 95 | + ) |
| 96 | + ) |
| 97 | + } |
| 98 | + |
| 99 | + private val executor: MultiLLMPromptExecutor = MultiLLMPromptExecutor(client) |
| 100 | + |
| 101 | + override fun getLLMClient(model: LLModel): LLMClient { |
| 102 | + require(model.provider == LLMProvider.Bedrock) { "Model ${model.id} is not a Bedrock model" } |
| 103 | + |
| 104 | + return client |
| 105 | + } |
| 106 | + |
| 107 | + override fun getExecutor(model: LLModel): PromptExecutor = executor |
| 108 | + |
| 109 | + override fun createReasoningParams(model: LLModel): LLMParams { |
| 110 | + require(model in reasoningCapableModels().toArray()) { |
| 111 | + "Model ${model.id} is not a reasoning capable model" |
| 112 | + } |
| 113 | + |
| 114 | + return BedrockConverseParams( |
| 115 | + additionalProperties = mapOf( |
| 116 | + // Anthropic-specific reasoning config |
| 117 | + "reasoning_config" to buildJsonObject { |
| 118 | + put("type", "enabled") |
| 119 | + put("budget_tokens", 1024) |
| 120 | + } |
| 121 | + ) |
| 122 | + ) |
| 123 | + } |
| 124 | + |
| 125 | + @ParameterizedTest |
| 126 | + @MethodSource("markdownScenarioModelCombinations") |
| 127 | + override fun integration_testMarkdownProcessingBasic( |
| 128 | + scenario: MarkdownTestScenario, |
| 129 | + model: LLModel |
| 130 | + ) { |
| 131 | + super.integration_testMarkdownProcessingBasic(scenario, model) |
| 132 | + } |
| 133 | + |
| 134 | + @ParameterizedTest |
| 135 | + @MethodSource("imageScenarioModelCombinations") |
| 136 | + override fun integration_testImageProcessing(scenario: ImageTestScenario, model: LLModel) { |
| 137 | + super.integration_testImageProcessing(scenario, model) |
| 138 | + } |
| 139 | + |
| 140 | + @ParameterizedTest |
| 141 | + @MethodSource("textScenarioModelCombinations") |
| 142 | + override fun integration_testTextProcessingBasic(scenario: TextTestScenario, model: LLModel) { |
| 143 | + super.integration_testTextProcessingBasic(scenario, model) |
| 144 | + } |
| 145 | + |
| 146 | + @Disabled("Converse API does not support audio processing") |
| 147 | + @ParameterizedTest |
| 148 | + @MethodSource("audioScenarioModelCombinations") |
| 149 | + override fun integration_testAudioProcessingBasic(scenario: AudioTestScenario, model: LLModel) { |
| 150 | + super.integration_testAudioProcessingBasic(scenario, model) |
| 151 | + } |
| 152 | + |
| 153 | + // Core integration test methods |
| 154 | + @ParameterizedTest |
| 155 | + @MethodSource("allCompletionModels") |
| 156 | + override fun integration_testExecute(model: LLModel) { |
| 157 | + super.integration_testExecute(model) |
| 158 | + } |
| 159 | + |
| 160 | + @ParameterizedTest |
| 161 | + @MethodSource("allCompletionModels") |
| 162 | + override fun integration_testExecuteStreaming(model: LLModel) { |
| 163 | + super.integration_testExecuteStreaming(model) |
| 164 | + } |
| 165 | + |
| 166 | + @ParameterizedTest |
| 167 | + @MethodSource("allCompletionModels") |
| 168 | + override fun integration_testExecuteStreamingWithTools(model: LLModel) { |
| 169 | + super.integration_testExecuteStreamingWithTools(model) |
| 170 | + } |
| 171 | + |
| 172 | + @ParameterizedTest |
| 173 | + @MethodSource("allCompletionModels") |
| 174 | + override fun integration_testToolWithRequiredParams(model: LLModel) { |
| 175 | + super.integration_testToolWithRequiredParams(model) |
| 176 | + } |
| 177 | + |
| 178 | + @ParameterizedTest |
| 179 | + @MethodSource("allCompletionModels") |
| 180 | + override fun integration_testToolWithNotRequiredOptionalParams(model: LLModel) { |
| 181 | + super.integration_testToolWithNotRequiredOptionalParams(model) |
| 182 | + } |
| 183 | + |
| 184 | + @ParameterizedTest |
| 185 | + @MethodSource("allCompletionModels") |
| 186 | + override fun integration_testToolWithOptionalParams(model: LLModel) { |
| 187 | + super.integration_testToolWithOptionalParams(model) |
| 188 | + } |
| 189 | + |
| 190 | + @ParameterizedTest |
| 191 | + @MethodSource("allCompletionModels") |
| 192 | + override fun integration_testToolWithNoParams(model: LLModel) { |
| 193 | + super.integration_testToolWithNoParams(model) |
| 194 | + } |
| 195 | + |
| 196 | + @ParameterizedTest |
| 197 | + @MethodSource("allCompletionModels") |
| 198 | + override fun integration_testToolWithListEnumParams(model: LLModel) { |
| 199 | + super.integration_testToolWithListEnumParams(model) |
| 200 | + } |
| 201 | + |
| 202 | + @ParameterizedTest |
| 203 | + @MethodSource("allCompletionModels") |
| 204 | + override fun integration_testToolWithNestedListParams(model: LLModel) { |
| 205 | + super.integration_testToolWithNestedListParams(model) |
| 206 | + } |
| 207 | + |
| 208 | + @ParameterizedTest |
| 209 | + @MethodSource("allCompletionModels") |
| 210 | + override fun integration_testToolsWithNullParams(model: LLModel) { |
| 211 | + super.integration_testToolsWithNullParams(model) |
| 212 | + } |
| 213 | + |
| 214 | + @ParameterizedTest |
| 215 | + @MethodSource("allCompletionModels") |
| 216 | + override fun integration_testToolsWithAnyOfParams(model: LLModel) { |
| 217 | + super.integration_testToolsWithAnyOfParams(model) |
| 218 | + } |
| 219 | + |
| 220 | + @ParameterizedTest |
| 221 | + @MethodSource("allCompletionModels") |
| 222 | + override fun integration_testMarkdownStructuredDataStreaming(model: LLModel) { |
| 223 | + super.integration_testMarkdownStructuredDataStreaming(model) |
| 224 | + } |
| 225 | + |
| 226 | + @ParameterizedTest |
| 227 | + @MethodSource("allCompletionModels") |
| 228 | + override fun integration_testToolChoiceRequired(model: LLModel) { |
| 229 | + super.integration_testToolChoiceRequired(model) |
| 230 | + } |
| 231 | + |
| 232 | + @Disabled("Converse API does not support tool choice none") |
| 233 | + @ParameterizedTest |
| 234 | + @MethodSource("allCompletionModels") |
| 235 | + override fun integration_testToolChoiceNone(model: LLModel) { |
| 236 | + super.integration_testToolChoiceNone(model) |
| 237 | + } |
| 238 | + |
| 239 | + @ParameterizedTest |
| 240 | + @MethodSource("allCompletionModels") |
| 241 | + override fun integration_testToolChoiceNamed(model: LLModel) { |
| 242 | + super.integration_testToolChoiceNamed(model) |
| 243 | + } |
| 244 | + |
| 245 | + @ParameterizedTest |
| 246 | + @MethodSource("allCompletionModels") |
| 247 | + override fun integration_testBase64EncodedAttachment(model: LLModel) { |
| 248 | + super.integration_testBase64EncodedAttachment(model) |
| 249 | + } |
| 250 | + |
| 251 | + @Disabled("Converse API supports only S3 url attachments") |
| 252 | + @ParameterizedTest |
| 253 | + @MethodSource("allCompletionModels") |
| 254 | + override fun integration_testUrlBasedAttachment(model: LLModel) { |
| 255 | + super.integration_testUrlBasedAttachment(model) |
| 256 | + } |
| 257 | + |
| 258 | + @Disabled("Converse API does ot support native structured output") |
| 259 | + @ParameterizedTest |
| 260 | + @MethodSource("allCompletionModels") |
| 261 | + override fun integration_testStructuredOutputNative(model: LLModel) { |
| 262 | + super.integration_testStructuredOutputNative(model) |
| 263 | + } |
| 264 | + |
| 265 | + @Disabled("Converse API does ot support native structured output") |
| 266 | + @ParameterizedTest |
| 267 | + @MethodSource("allCompletionModels") |
| 268 | + override fun integration_testStructuredOutputNativeWithFixingParser(model: LLModel) { |
| 269 | + super.integration_testStructuredOutputNativeWithFixingParser(model) |
| 270 | + } |
| 271 | + |
| 272 | + @ParameterizedTest |
| 273 | + @MethodSource("allCompletionModels") |
| 274 | + override fun integration_testStructuredOutputManual(model: LLModel) { |
| 275 | + super.integration_testStructuredOutputManual(model) |
| 276 | + } |
| 277 | + |
| 278 | + @ParameterizedTest |
| 279 | + @MethodSource("allCompletionModels") |
| 280 | + override fun integration_testStructuredOutputManualWithFixingParser(model: LLModel) { |
| 281 | + super.integration_testStructuredOutputManualWithFixingParser(model) |
| 282 | + } |
| 283 | + |
| 284 | + @ParameterizedTest |
| 285 | + @MethodSource("allCompletionModels") |
| 286 | + override fun integration_testMultipleSystemMessages(model: LLModel) { |
| 287 | + super.integration_testMultipleSystemMessages(model) |
| 288 | + } |
| 289 | + |
| 290 | + @ParameterizedTest |
| 291 | + @MethodSource("reasoningCapableModels") |
| 292 | + override fun integration_testReasoningCapability(model: LLModel) { |
| 293 | + super.integration_testReasoningCapability(model) |
| 294 | + } |
| 295 | + |
| 296 | + @ParameterizedTest |
| 297 | + @MethodSource("reasoningCapableModels") |
| 298 | + override fun integration_testReasoningMultiStep(model: LLModel) { |
| 299 | + super.integration_testReasoningMultiStep(model) |
| 300 | + } |
| 301 | +} |
0 commit comments