|
| 1 | +package com.sap.ai.sdk.orchestration; |
| 2 | + |
| 3 | +import static com.sap.ai.sdk.orchestration.AzureModerationPolicy.ALLOW_SAFE_LOW_MEDIUM; |
| 4 | +import static org.assertj.core.api.Assertions.assertThat; |
| 5 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 6 | + |
| 7 | +import com.sap.ai.sdk.orchestration.client.model.LLMModuleConfig; |
| 8 | +import java.util.Map; |
| 9 | +import org.junit.jupiter.api.BeforeEach; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | + |
| 12 | +class OrchestrationModuleConfigTest { |
| 13 | + |
| 14 | + private OrchestrationModuleConfig config; |
| 15 | + |
| 16 | + @BeforeEach |
| 17 | + void setUp() { |
| 18 | + final var llmModuleConfig = |
| 19 | + new LLMModuleConfig().modelName("gpt-35-turbo").modelParams(Map.of()); |
| 20 | + config = new OrchestrationModuleConfig().withLlmConfig(llmModuleConfig); |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + void testStackingInputAndOutputFilter() { |
| 25 | + final var filter = |
| 26 | + new AzureContentFilter() |
| 27 | + .hate(ALLOW_SAFE_LOW_MEDIUM) |
| 28 | + .selfHarm(ALLOW_SAFE_LOW_MEDIUM) |
| 29 | + .sexual(ALLOW_SAFE_LOW_MEDIUM) |
| 30 | + .violence(ALLOW_SAFE_LOW_MEDIUM); |
| 31 | + |
| 32 | + final var configWithInputFirst = config.withInputFiltering(filter).withOutputFiltering(filter); |
| 33 | + assertThat(configWithInputFirst.getFilteringConfig()).isNotNull(); |
| 34 | + assertThat(configWithInputFirst.getFilteringConfig().getInput()).isNotNull(); |
| 35 | + |
| 36 | + final var configWithOutputFirst = config.withOutputFiltering(filter).withInputFiltering(filter); |
| 37 | + assertThat(configWithOutputFirst.getFilteringConfig()).isNotNull(); |
| 38 | + assertThat(configWithOutputFirst.getFilteringConfig().getOutput()).isNotNull(); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + void testThrowOnEmptyFilterConfig() { |
| 43 | + final var filter = new AzureContentFilter(); |
| 44 | + |
| 45 | + assertThatThrownBy(() -> config.withInputFiltering(filter)) |
| 46 | + .isInstanceOf(IllegalArgumentException.class) |
| 47 | + .hasMessage("At least one filter moderation policy must be set"); |
| 48 | + assertThatThrownBy(() -> config.withOutputFiltering(filter)) |
| 49 | + .isInstanceOf(IllegalArgumentException.class) |
| 50 | + .hasMessage("At least one filter moderation policy must be set"); |
| 51 | + } |
| 52 | +} |
0 commit comments