Skip to content

Commit 4a30c26

Browse files
Used lombok @with
1 parent 9195bde commit 4a30c26

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

orchestration/src/main/java/com/sap/ai/sdk/orchestration/DpiMasking.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import lombok.Getter;
1818
import lombok.RequiredArgsConstructor;
1919
import lombok.Value;
20+
import lombok.With;
2021
import lombok.val;
2122

2223
/**
@@ -32,7 +33,7 @@
3233
public class DpiMasking implements MaskingProvider {
3334
@Nonnull DPIConfig.MethodEnum maskingMethod;
3435
@Nonnull List<DPIEntities> entities;
35-
boolean maskGroundingInput;
36+
@With boolean maskGroundingInput;
3637
@Nonnull List<String> allowList;
3738

3839
/**
@@ -81,16 +82,6 @@ public DpiMasking withEntities(
8182
}
8283
}
8384

84-
/**
85-
* If grounding is used, the input text will be masked.
86-
*
87-
* @return A new {@link DpiMasking} instance
88-
*/
89-
@Nonnull
90-
public DpiMasking withMaskGroundingEnabled() {
91-
return new DpiMasking(maskingMethod, entities, true, allowList);
92-
}
93-
9485
/**
9586
* Set words that should not be masked.
9687
*

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationModuleConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void testDpiMaskingConfig() {
8080
var maskingConfig =
8181
DpiMasking.anonymization()
8282
.withEntities(DPIEntities.ADDRESS)
83-
.withMaskGroundingEnabled()
83+
.withMaskGroundingInput(true)
8484
.withAllowList(List.of("Alice"));
8585
var config =
8686
new OrchestrationModuleConfig().withLlmConfig(GPT_4O).withMaskingConfig(maskingConfig);

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void testGrounding() throws IOException {
173173
val maskingConfig = // optional masking configuration
174174
DpiMasking.anonymization()
175175
.withEntities(DPIEntities.SENSITIVE_DATA)
176-
.withMaskGroundingEnabled()
176+
.withMaskGroundingInput(true)
177177
.withAllowList(List.of("SAP", "Joule"));
178178
final var configWithGrounding =
179179
config.withGroundingConfig(groundingConfig).withMaskingConfig(maskingConfig);
@@ -215,7 +215,7 @@ void testGrounding() throws IOException {
215215
Map.of(
216216
"masked_template",
217217
"[{\"role\": \"user\", \"content\": \"Context message with embedded grounding results. First chunk```MASKED_SENSITIVE_DATA```Last found chunk\"}]",
218-
"masked_grounding_input",
218+
"masked_grounding_input", // maskGroundingInput: true will make this field present
219219
"[\"What does Joule do?\"]"));
220220

221221
try (var requestInputStream = fileLoader.apply("groundingRequest.json")) {

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ Object maskingPseudonymization(
180180
return response.getContent();
181181
}
182182

183-
@GetMapping("/grounding")
183+
@GetMapping("/grounding/{maskGroundingInput}")
184184
@Nonnull
185185
Object grounding(
186-
@Nullable @RequestParam(value = "format", required = false) final String format) {
187-
final var response = service.grounding("What does Joule do?");
186+
@Nullable @RequestParam(value = "format", required = false) final String format,
187+
@PathVariable("maskGroundingInput") final boolean maskGroundingInput) {
188+
final var response = service.grounding("What does Joule do?", maskGroundingInput);
188189
if ("json".equals(format)) {
189190
return response;
190191
}

sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ public OrchestrationChatResponse maskingPseudonymization(@Nonnull final DPIEntit
316316
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/grounding">SAP
317317
* AI Core: Orchestration - Grounding</a>
318318
* @param userMessage the user message to provide grounding for
319+
* @param maskGroundingInput whether to mask the request sent to the Grounding Service
319320
* @return the assistant response object
320321
*/
321322
@Nonnull
322-
public OrchestrationChatResponse grounding(@Nonnull final String userMessage) {
323+
public OrchestrationChatResponse grounding(
324+
@Nonnull final String userMessage, final boolean maskGroundingInput) {
323325
// optional filter for collections
324326
val documentMetadata =
325327
SearchDocumentKeyValueListPair.create()
@@ -338,7 +340,7 @@ public OrchestrationChatResponse grounding(@Nonnull final String userMessage) {
338340
val maskingConfig = // optional masking configuration
339341
DpiMasking.anonymization()
340342
.withEntities(DPIEntities.SENSITIVE_DATA)
341-
.withMaskGroundingEnabled()
343+
.withMaskGroundingInput(maskGroundingInput)
342344
.withAllowList(List.of("SAP", "Joule"));
343345
val configWithGrounding =
344346
config.withGrounding(groundingConfig).withMaskingConfig(maskingConfig);

sample-code/spring-app/src/main/resources/static/index.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ <h2>Orchestration</h2>
340340
</li>
341341
<li class="list-group-item">
342342
<div class="info-tooltip">
343-
<button type="submit" formaction="/orchestration/grounding"
343+
<button type="submit" formaction="/orchestration/grounding/false"
344344
class="link-offset-2-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover endpoint">
345345
<code>/orchestration/grounding</code>
346346
</button>
@@ -349,6 +349,17 @@ <h2>Orchestration</h2>
349349
</div>
350350
</div>
351351
</li>
352+
<li class="list-group-item">
353+
<div class="info-tooltip">
354+
<button type="submit" formaction="/orchestration/grounding/true"
355+
class="link-offset-2-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover endpoint">
356+
<code>/orchestration/<wbr>maskGroundingInput</code>
357+
</button>
358+
<div class="tooltip-content">
359+
The request to the grounding service will be masked.
360+
</div>
361+
</div>
362+
</li>
352363

353364
<li class="list-group-item">
354365
<div class="info-tooltip">

sample-code/spring-app/src/test/java/com/sap/ai/sdk/app/controllers/OrchestrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void testMaskingPseudonymization() {
167167
@DisabledIfSystemProperty(named = "aicore.landscape", matches = "production")
168168
void testGrounding() {
169169
assertThat(System.getProperty("aicore.landscape")).isNotEqualTo("production");
170-
var response = service.grounding("What does Joule do?");
170+
var response = service.grounding("What does Joule do?", true);
171171
var result = response.getOriginalResponse();
172172
var llmChoice =
173173
((LLMModuleResultSynchronous) result.getOrchestrationResult()).getChoices().get(0);

0 commit comments

Comments
 (0)