You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please also refer to [our sample code](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java) for this and all following code examples.
84
+
85
+
### Chat Completion
83
86
84
-
var config =
85
-
CompletionPostRequest.create()
86
-
.orchestrationConfig(
87
-
OrchestrationConfig.create()
88
-
.moduleConfigurations(
89
-
ModuleConfigs.create()
90
-
.llmModuleConfig(llmConfig)
91
-
.templatingModuleConfig(templatingConfig)))
92
-
.inputParams(inputParams);
87
+
Use the Orchestration service to generate a response to a user message:
88
+
89
+
```java
90
+
var prompt =newOrchestrationPrompt("Hello world! Why is this phrase so famous?");
93
91
94
-
CompletionPostResponse result =
95
-
new OrchestrationClient().chatCompletion(config);
92
+
var result = client.chatCompletion(prompt, config);
See [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java)
98
+
In this example, the Orchestration service generates a response to the user message "Hello world! Why is this phrase so famous?".
99
+
The LLM response is available as the first choice under the `result.getOrchestrationResult()` object.
102
100
103
-
### Message history
101
+
### Chat completion with Templates
104
102
105
-
Include a message history to maintain context in the conversation:
103
+
Use a prepared template and execute requests with by passing only the input parameters:
106
104
107
105
```java
108
-
var llmConfig =LLMModuleConfig.create().modelName("gpt-35-turbo").modelParams(Map.of());
106
+
var template =ChatMessage.create().role("user").content("{{?input}}");
107
+
var templatingConfig =TemplatingModuleConfig.create().template(template);
109
108
110
-
List<ChatMessage> messagesHistory =
111
-
List.of(
112
-
ChatMessage.create().role("user").content("What is the capital of France?"),
113
-
ChatMessage.create().role("assistant").content("The capital of France is Paris."));
109
+
var inputParams =
110
+
Map.of("input", "Reply with 'Orchestration Service is working!' in German");
111
+
var prompt =newOrchestrationPrompt(inputParams);
114
112
113
+
var result = client.chatCompletion(prompt, config.withTemplateConfig(templatingConfig));
114
+
```
115
+
116
+
### Message history
117
+
118
+
Include a message history to maintain context in the conversation:
119
+
120
+
```java
121
+
var messagesHistory =
122
+
List.of(
123
+
ChatMessage.create().role("user").content("What is the capital of France?"),
124
+
ChatMessage.create().role("assistant").content("The capital of France is Paris."));
115
125
var message =
116
-
ChatMessage.create().role("user").content("What is the typical food there?");
117
-
var templatingConfig =TemplatingModuleConfig.create().template(message);
118
-
119
-
var config =
120
-
CompletionPostRequest.create()
121
-
.orchestrationConfig(
122
-
OrchestrationConfig.create()
123
-
.moduleConfigurations(
124
-
ModuleConfigs.create()
125
-
.llmModuleConfig(llmConfig)
126
-
.templatingModuleConfig(templatingConfig)))
127
-
.messagesHistory(messagesHistory);
128
-
129
-
CompletionPostResponse result =
130
-
newOrchestrationClient().chatCompletion(config);
126
+
ChatMessage.create().role("user").content("What is the typical food there?");
var prompt =newOrchestrationPrompt(message).messageHistory(messagesHistory);
135
129
136
-
See [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java)
130
+
var result =newOrchestrationClient().chatCompletion(prompt, config);
131
+
```
137
132
138
133
### Chat completion filter
139
134
140
135
Apply content filtering to the chat completion:
141
136
142
137
```java
143
-
var llmConfig =LLMModuleConfig.create().modelName("gpt-35-turbo").modelParams(Map.of());
144
-
145
-
var inputParams =
146
-
Map.of(
147
-
"disclaimer",
148
-
"```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent.");
149
-
var template =
150
-
ChatMessage.create()
151
-
.role("user")
152
-
.content(
153
-
"Create a rental posting for subletting my apartment in the downtown area. Keep it short. Make sure to add the following disclaimer to the end. Do not change it! {{?disclaimer}}");
154
-
var templatingConfig =TemplatingModuleConfig.create().template(template);
138
+
var prompt =newOrchestrationPrompt(
139
+
"""
140
+
Create a rental posting for subletting my apartment in the downtown area. Keep it short. Make sure to add the following disclaimer to the end. Do not change it!
141
+
142
+
```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent.
143
+
""");
155
144
156
145
var filterStrict =
157
146
FilterConfig.create()
@@ -176,40 +165,19 @@ var filterLoose =
176
165
var filteringConfig =
177
166
FilteringModuleConfig.create()
178
167
// changing the input to filterLoose will allow the message to pass
See [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java)
202
-
203
176
### Data masking
204
177
205
178
Use the data masking module to anonymize personal information in the input:
206
179
207
180
```java
208
-
var inputParams =Map.of("privateInfo", "Patrick Morgan +49 (970) 333-3833");
209
-
var template =
210
-
ChatMessage.create().role("user").content("What is the nationality of {{?privateInfo}}");
211
-
var templatingConfig =TemplatingModuleConfig.create().template(template);
In this example, the input will be masked before the call to the LLM. Note that data cannot be unmasked in the LLM output.
241
207
242
-
See [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/controllers/OrchestrationController.java)
243
-
244
208
### Set model parameters
245
209
246
210
Change your LLM module configuration to add model parameters:
0 commit comments