11package com .sap .ai .sdk .orchestration ;
22
33import static com .sap .ai .sdk .orchestration .AzureModerationPolicy .ALLOW_SAFE_LOW_MEDIUM ;
4+ import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .GPT_4O ;
45import static org .assertj .core .api .Assertions .assertThat ;
56import static org .assertj .core .api .Assertions .assertThatThrownBy ;
67
7- import com .sap .ai .sdk .orchestration .client .model .LLMModuleConfig ;
8+ import com .sap .ai .sdk .orchestration .client .model .DPIConfig ;
9+ import com .sap .ai .sdk .orchestration .client .model .DPIEntities ;
810import java .util .Map ;
9- import org .junit .jupiter .api .BeforeEach ;
1011import org .junit .jupiter .api .Test ;
1112
1213class OrchestrationModuleConfigTest {
1314
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-
2315 @ Test
2416 void testStackingInputAndOutputFilter () {
17+ final var config = new OrchestrationModuleConfig ().withLlmConfig (GPT_4O );
18+
2519 final var filter =
2620 new AzureContentFilter ()
2721 .hate (ALLOW_SAFE_LOW_MEDIUM )
@@ -40,13 +34,54 @@ void testStackingInputAndOutputFilter() {
4034
4135 @ Test
4236 void testThrowOnEmptyFilterConfig () {
43- final var filter = new AzureContentFilter ();
4437
45- assertThatThrownBy (() -> config .withInputFiltering (filter ))
38+ final var config = new OrchestrationModuleConfig ().withLlmConfig (GPT_4O );
39+
40+ assertThatThrownBy (() -> config .withInputFiltering (new AzureContentFilter ()))
4641 .isInstanceOf (IllegalArgumentException .class )
4742 .hasMessage ("At least one filter moderation policy must be set" );
48- assertThatThrownBy (() -> config .withOutputFiltering (filter ))
43+ assertThatThrownBy (() -> config .withOutputFiltering (new AzureContentFilter () ))
4944 .isInstanceOf (IllegalArgumentException .class )
5045 .hasMessage ("At least one filter moderation policy must be set" );
5146 }
47+
48+ @ Test
49+ void testDpiMaskingConfig () {
50+ var maskingConfig = DpiMasking .anonymization ().withEntities (DPIEntities .ADDRESS );
51+ var config =
52+ new OrchestrationModuleConfig ().withLlmConfig (GPT_4O ).withMaskingConfig (maskingConfig );
53+
54+ assertThat (config .getMaskingConfig ()).isNotNull ();
55+ assertThat (config .getMaskingConfig ().getMaskingProviders ()).hasSize (1 );
56+ DPIConfig dpiConfig = (DPIConfig ) config .getMaskingConfig ().getMaskingProviders ().get (0 );
57+ assertThat (dpiConfig .getMethod ()).isEqualTo (DPIConfig .MethodEnum .ANONYMIZATION );
58+ assertThat (dpiConfig .getEntities ()).hasSize (1 );
59+ assertThat (dpiConfig .getEntities ().get (0 ).getType ()).isEqualTo (DPIEntities .ADDRESS );
60+
61+ var configModified = config .withMaskingConfig (maskingConfig );
62+ assertThat (configModified .getMaskingConfig ()).isNotNull ();
63+ assertThat (configModified .getMaskingConfig ().getMaskingProviders ())
64+ .withFailMessage ("withMaskingConfig() should overwrite the existing config and not append" )
65+ .hasSize (1 );
66+ }
67+
68+ @ Test
69+ void testLLMConfig () {
70+ Map <String , Object > params = Map .of ("foo" , "bar" );
71+ String version = "2024-05-13" ;
72+ OrchestrationAiModel aiModel = GPT_4O .withModelParams (params ).withModelVersion (version );
73+ var config = new OrchestrationModuleConfig ().withLlmConfig (aiModel );
74+
75+ assertThat (config .getLlmConfig ()).isNotNull ();
76+ assertThat (config .getLlmConfig ().getModelName ()).isEqualTo (GPT_4O .getModelName ());
77+ assertThat (config .getLlmConfig ().getModelParams ()).isEqualTo (params );
78+ assertThat (config .getLlmConfig ().getModelVersion ()).isEqualTo (version );
79+
80+ assertThat (GPT_4O .getModelParams ())
81+ .withFailMessage ("Static models should be unchanged" )
82+ .isEmpty ();
83+ assertThat (GPT_4O .getModelVersion ())
84+ .withFailMessage ("Static models should be unchanged" )
85+ .isEqualTo ("latest" );
86+ }
5287}
0 commit comments