Skip to content

Commit dd753cb

Browse files
committed
Fixing PR comments
1 parent 42852cb commit dd753cb

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String r
105105
}
106106
}
107107

108+
/**
109+
* Specifies a custom regex pattern for masking.
110+
*
111+
* @param regex The regex pattern to match
112+
* @param replacement The replacement string
113+
* @return A new {@link DpiMasking} instance
114+
*/
115+
@Nonnull
116+
public DpiMasking withRegex(@Nonnull final String regex, @Nonnull final String replacement) {
117+
return new DpiMasking(maskingMethod, entities, customEntities, maskGroundingInput, allowList);
118+
}
119+
108120
/**
109121
* Set words that should not be masked.
110122
*

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ Object maskingAnonymization(
216216
return response.getContent();
217217
}
218218

219+
@GetMapping("/maskingRegex")
220+
@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();
228+
}
229+
219230
@GetMapping("/completion/{resourceGroup}")
220231
@Nonnull
221232
Object completionWithResourceGroup(

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

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

275275
return client.chatCompletion(prompt, configWithMasking);
276276
}
277-
278-
/**
279-
* Let the orchestration service evaluate the feedback on the AI SDK provided by a hypothetical
280-
* user. Anonymize any patient IDs given as they are not relevant for judging the sentiment of the
281-
* feedback.
282-
*
283-
* @link <a
284-
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/data-masking">SAP AI
285-
* Core: Orchestration - Data Masking</a>
286-
* @return the assistant response object
287-
*/
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+
*/
288287
@Nonnull
289-
public OrchestrationChatResponse maskingCustomAnonymization() {
288+
public OrchestrationChatResponse maskingRegex() {
290289
val systemMessage = Message.system("Repeat following messages");
291290
val userMessage = Message.user("The patient id is patient_id_123.");
292291

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,23 @@ <h2>Orchestration</h2>
380380
</div>
381381
</div>
382382
</li>
383+
<li class="list-group-item">
384+
<div class="info-tooltip">
385+
<button type="submit"
386+
formaction="/orchestration/maskingRegex"
387+
class="link-offset-2-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover endpoint">
388+
<code>/orchestration/maskingRegex</code>
389+
</button>
390+
<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.
397+
</div>
398+
</div>
399+
</li>
383400
<li class="list-group-item">
384401
<div class="info-tooltip">
385402
<button type="submit"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ void testMaskingAnonymization() {
151151
}
152152

153153
@Test
154-
void testMaskingCustomAnonymization() {
155-
var response = service.maskingCustomAnonymization();
154+
void testMaskingRegex() {
155+
var response = service.maskingRegex();
156156
var result = response.getOriginalResponse();
157157
var llmChoice = result.getFinalResult().getChoices().get(0);
158158
assertThat(llmChoice.getFinishReason()).isEqualTo("stop");

0 commit comments

Comments
 (0)