Skip to content

Commit 821cb9c

Browse files
committed
Updates
1 parent 6acd521 commit 821cb9c

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
3535
public class DpiMasking implements MaskingProvider {
3636
@Nonnull DPIConfig.MethodEnum maskingMethod;
37-
@Nonnull List<DPIEntities> entities;
38-
@Nonnull List<DPICustomEntity> customEntities;
37+
@Nonnull List<DPIEntityConfig> entitiesDTO;
3938
@With boolean maskGroundingInput;
4039
@Nonnull List<String> allowList;
4140

@@ -81,7 +80,13 @@ public DpiMasking withEntities(
8180
val entitiesList = new ArrayList<DPIEntities>();
8281
entitiesList.add(entity);
8382
entitiesList.addAll(Arrays.asList(entities));
84-
return new DpiMasking(maskingMethod, entitiesList, List.of(), false, List.of());
83+
84+
val entitiesDTO =
85+
new ArrayList<>(
86+
entitiesList.stream()
87+
.map(it -> (DPIEntityConfig) DPIStandardEntity.create().type(it))
88+
.toList());
89+
return new DpiMasking(maskingMethod, entitiesDTO, false, List.of());
8590
}
8691

8792
/**
@@ -101,7 +106,7 @@ public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String r
101106
.method(DPIMethodConstant.MethodEnum.CONSTANT)
102107
.value(replacement));
103108

104-
return new DpiMasking(maskingMethod, List.of(), List.of(customEntity), false, List.of());
109+
return new DpiMasking(maskingMethod, List.of(customEntity), false, List.of());
105110
}
106111
}
107112

@@ -114,7 +119,7 @@ public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String r
114119
*/
115120
@Nonnull
116121
public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String replacement) {
117-
return new DpiMasking(maskingMethod, entities, customEntities, maskGroundingInput, allowList);
122+
return new DpiMasking(maskingMethod, entitiesDTO, maskGroundingInput, allowList);
118123
}
119124

120125
/**
@@ -125,18 +130,12 @@ public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String r
125130
*/
126131
@Nonnull
127132
public DpiMasking withAllowList(@Nonnull final List<String> allowList) {
128-
return new DpiMasking(maskingMethod, entities, customEntities, maskGroundingInput, allowList);
133+
return new DpiMasking(maskingMethod, entitiesDTO, maskGroundingInput, allowList);
129134
}
130135

131136
@Nonnull
132137
@Override
133138
public DPIConfig createConfig() {
134-
val entitiesDTO =
135-
new ArrayList<>(
136-
entities.stream()
137-
.map(it -> (DPIEntityConfig) DPIStandardEntity.create().type(it))
138-
.toList());
139-
entitiesDTO.addAll(customEntities);
140139
return DPIConfig.create()
141140
.type(SAP_DATA_PRIVACY_INTEGRATION)
142141
.method(maskingMethod)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ Object maskingAnonymization(
218218

219219
@GetMapping("/maskingRegex")
220220
@Nonnull
221-
Object maskingRegex(
222-
@Nullable @RequestParam(value = "format", required = false) final String format) {
223-
final var response = service.maskingRegex();
224-
if ("json".equals(format)) {
225-
return response;
226-
}
227-
return response.getContent();
221+
Object maskingRegex(
222+
@Nullable @RequestParam(value = "format", required = false) final String format) {
223+
final var response = service.maskingRegex();
224+
if ("json".equals(format)) {
225+
return response;
228226
}
227+
return response.getContent();
228+
}
229229

230230
@GetMapping("/completion/{resourceGroup}")
231231
@Nonnull

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,15 @@ public OrchestrationChatResponse maskingAnonymization(@Nonnull final DPIEntities
274274

275275
return client.chatCompletion(prompt, configWithMasking);
276276
}
277-
/**
278-
* Let the orchestration service evaluate the feedback on the AI SDK provided by a hypothetical
279-
* user. Mask any patient IDs given as they are not relevant for judging the sentiment of the
280-
* feedback.
281-
*
282-
* @link <a
283-
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-masking">SAP AI
284-
* Core: Orchestration - Data Masking</a>
285-
* @return the assistant response object
286-
*/
277+
278+
/**
279+
* Let the LLM respond with a masked repeated phrase of patient IDs.
280+
*
281+
* @link <a
282+
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-masking">SAP AI
283+
* Core: Orchestration - Data Masking</a>
284+
* @return the assistant response object
285+
*/
287286
@Nonnull
288287
public OrchestrationChatResponse maskingRegex() {
289288
val systemMessage = Message.system("Repeat following messages");
@@ -292,7 +291,10 @@ public OrchestrationChatResponse maskingRegex() {
292291
val prompt = new OrchestrationPrompt(systemMessage, userMessage);
293292
val regex = "patient_id_[0-9]+";
294293
val replacement = "REDACTED_ID";
295-
val maskingConfig = DpiMasking.anonymization().withRegex(regex, replacement);
294+
val maskingConfig =
295+
DpiMasking.anonymization()
296+
.withRegex(regex, replacement)
297+
.withRegex("student_id_[0-9]+", "student_id");
296298
val configWithMasking = config.withMaskingConfig(maskingConfig);
297299

298300
return client.chatCompletion(prompt, configWithMasking);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,7 @@ <h2>Orchestration</h2>
388388
<code>/orchestration/maskingRegex</code>
389389
</button>
390390
<div class="tooltip-content">
391-
Let the orchestration service evaluate the feedback on
392-
the AI SDK provided by a
393-
hypothetical
394-
user. Mask any patient IDs given as they are not relevant for judging the
395-
sentiment of the
396-
feedback.
391+
Let the LLM respond with a masked repeated phrase of patient IDs.
397392
</div>
398393
</div>
399394
</li>

0 commit comments

Comments
 (0)