Skip to content

Commit 9a92818

Browse files
committed
Minor tweaks
1 parent 9cfa2ec commit 9a92818

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

docs/guides/ORCHESTRATION_CHAT_COMPLETION.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,18 @@ The LLM response is available as the first choice under the `result.getOrchestra
103103
Use a prepared template and execute requests with by passing only the input parameters:
104104

105105
```java
106-
var template = ChatMessage.create().role("user").content("{{?input}}");
106+
var template = ChatMessage.create().role("user").content("Reply with 'Orchestration Service is working!' in {{?language}}");
107107
var templatingConfig = TemplatingModuleConfig.create().template(template);
108+
var configWithTemplate = config.withTemplateConfig(templatingConfig);
108109

109-
var inputParams =
110-
Map.of("input", "Reply with 'Orchestration Service is working!' in German");
110+
var inputParams = Map.of("language", "German");
111111
var prompt = new OrchestrationPrompt(inputParams);
112112

113-
var result = client.chatCompletion(prompt, config.withTemplateConfig(templatingConfig));
113+
var result = client.chatCompletion(prompt, configWithTemplate);
114114
```
115115

116+
In this case the template is defined with the placeholder `{{?language}}` which is replaced by the value `German` in the input parameters.
117+
116118
### Message history
117119

118120
Include a message history to maintain context in the conversation:
@@ -168,9 +170,11 @@ var filteringConfig =
168170
.input(InputFilteringConfig.create().filters(filterStrict))
169171
.output(OutputFilteringConfig.create().filters(filterStrict));
170172

173+
var configWithFilter = config.withFilteringConfig(filteringConfig);
174+
171175
// this fails with Bad Request because the strict filter prohibits the input message
172176
var result =
173-
new OrchestrationClient().chatCompletion(prompt, config.withFilteringConfig(filteringConfig));
177+
new OrchestrationClient().chatCompletion(prompt, configWithFilter);
174178
```
175179

176180
### Data masking
@@ -186,6 +190,7 @@ var maskingProvider =
186190
DPIEntityConfig.create().type(DPIEntities.PHONE),
187191
DPIEntityConfig.create().type(DPIEntities.PERSON));
188192
var maskingConfig = MaskingModuleConfig.create().maskingProviders(maskingProvider);
193+
var configWithMasking = config.withMaskingConfig(maskingConfig);
189194

190195
var systemMessage = ChatMessage.create()
191196
.role("system")
@@ -200,7 +205,7 @@ var userMessage = ChatMessage.create()
200205
var prompt = new OrchestrationPrompt(systemMessage, userMessage);
201206

202207
var result =
203-
new OrchestrationClient().chatCompletion(prompt, config.withMaskingConfig(maskingConfig));
208+
new OrchestrationClient().chatCompletion(prompt, configWithMasking);
204209
```
205210

206211
In this example, the input will be masked before the call to the LLM. Note that data cannot be unmasked in the LLM output.

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public CompletionPostResponse completion() {
5858
@GetMapping("/template")
5959
@Nonnull
6060
public CompletionPostResponse template() {
61-
final var template = ChatMessage.create().role("user").content("{{?input}}");
61+
final var template = ChatMessage.create().role("user").content("Reply with 'Orchestration Service is working!' in {{?language}}");
6262
final var templatingConfig = TemplatingModuleConfig.create().template(template);
63+
final var configWithTemplate = config.withTemplateConfig(templatingConfig);
6364

64-
final var inputParams =
65-
Map.of("input", "Reply with 'Orchestration Service is working!' in German");
66-
65+
final var inputParams = Map.of("language", "German");
6766
final var prompt = new OrchestrationPrompt(inputParams);
68-
return client.chatCompletion(prompt, config.withTemplateConfig(templatingConfig));
67+
68+
return client.chatCompletion(prompt, configWithTemplate);
6969
}
7070

7171
/**
@@ -106,8 +106,9 @@ public CompletionPostResponse filter(
106106
```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent.
107107
""");
108108
final var filterConfig = createAzureContentFilter(threshold);
109+
final var configWithFilter = config.withFilteringConfig(filterConfig);
109110

110-
return client.chatCompletion(prompt, config.withFilteringConfig(filterConfig));
111+
return client.chatCompletion(prompt, configWithFilter);
111112
}
112113

113114
/**
@@ -160,8 +161,9 @@ public CompletionPostResponse maskingAnonymization() {
160161
final var prompt = new OrchestrationPrompt(systemMessage, userMessage);
161162
final var maskingConfig =
162163
createMaskingConfig(MaskingProviderConfig.MethodEnum.ANONYMIZATION, DPIEntities.PERSON);
164+
final var configWithMasking = config.withMaskingConfig(maskingConfig);
163165

164-
return client.chatCompletion(prompt, config.withMaskingConfig(maskingConfig));
166+
return client.chatCompletion(prompt, configWithMasking);
165167
}
166168

167169
/**
@@ -200,8 +202,9 @@ public CompletionPostResponse maskingPseudonymization() {
200202
MaskingProviderConfig.MethodEnum.PSEUDONYMIZATION,
201203
DPIEntities.PERSON,
202204
DPIEntities.EMAIL);
205+
final var configWithMasking = config.withMaskingConfig(maskingConfig);
203206

204-
return client.chatCompletion(prompt, config.withMaskingConfig(maskingConfig));
207+
return client.chatCompletion(prompt, configWithMasking);
205208
}
206209

207210
/**

0 commit comments

Comments
 (0)