11package com .sap .ai .sdk .app .services ;
22
33import static com .sap .ai .sdk .app .controllers .OpenAiController .send ;
4- import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .GPT_35_TURBO ;
4+ import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .GEMINI_1_5_FLASH ;
55import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .TEMPERATURE ;
66
77import com .sap .ai .sdk .core .AiCoreService ;
@@ -38,16 +38,16 @@ public class OrchestrationService {
3838
3939 @ Getter
4040 private final OrchestrationModuleConfig config =
41- new OrchestrationModuleConfig ().withLlmConfig (GPT_35_TURBO .withParam (TEMPERATURE , 0.0 ));
41+ new OrchestrationModuleConfig ().withLlmConfig (GEMINI_1_5_FLASH .withParam (TEMPERATURE , 0.0 ));
4242
4343 /**
4444 * Chat request to OpenAI through the Orchestration service with a simple prompt.
4545 *
4646 * @return the assistant response object
4747 */
4848 @ Nonnull
49- public OrchestrationChatResponse completion () {
50- final var prompt = new OrchestrationPrompt ("Hello world! Why is this phrase so famous?" );
49+ public OrchestrationChatResponse completion (@ Nonnull final String famousPhrase ) {
50+ final var prompt = new OrchestrationPrompt (famousPhrase + " Why is this phrase so famous?" );
5151 return client .chatCompletion (prompt , config );
5252 }
5353
@@ -59,13 +59,13 @@ public OrchestrationChatResponse completion() {
5959 * @return the assistant response object
6060 */
6161 @ Nonnull
62- public OrchestrationChatResponse template () {
62+ public OrchestrationChatResponse template (@ Nonnull final String language ) {
6363 final var template =
6464 Message .user ("Reply with 'Orchestration Service is working!' in {{?language}}" );
6565 final var templatingConfig = Template .create ().template (List .of (template .createChatMessage ()));
6666 final var configWithTemplate = config .withTemplateConfig (templatingConfig );
6767
68- final var inputParams = Map .of ("language" , "German" );
68+ final var inputParams = Map .of ("language" , language );
6969 final var prompt = new OrchestrationPrompt (inputParams );
7070
7171 return client .chatCompletion (prompt , configWithTemplate );
@@ -77,8 +77,8 @@ public OrchestrationChatResponse template() {
7777 * @return the assistant response object
7878 */
7979 @ Nonnull
80- public OrchestrationChatResponse messagesHistory () {
81- final var prompt = new OrchestrationPrompt (Message .user ("What is the capital of France?" ));
80+ public OrchestrationChatResponse messagesHistory (@ Nonnull final String prevMessage ) {
81+ final var prompt = new OrchestrationPrompt (Message .user (prevMessage ));
8282
8383 final var result = client .chatCompletion (prompt , config );
8484
@@ -103,14 +103,16 @@ public OrchestrationChatResponse messagesHistory() {
103103 * @return the assistant response object
104104 */
105105 @ Nonnull
106- public OrchestrationChatResponse filter (@ Nonnull final AzureFilterThreshold policy ) {
106+ public OrchestrationChatResponse filter (
107+ @ Nonnull final AzureFilterThreshold policy , @ Nonnull final String area ) {
107108 final var prompt =
108109 new OrchestrationPrompt (
109110 """
110- 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!
111+ Create a rental posting for subletting my apartment in %s . Keep it short. Make sure to add the following disclaimer to the end. Do not change it!
111112
112113 ```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent.
113- """ );
114+ """
115+ .formatted (area ));
114116 final var filterConfig =
115117 new AzureContentFilter ().hate (policy ).selfHarm (policy ).sexual (policy ).violence (policy );
116118
@@ -131,7 +133,7 @@ public OrchestrationChatResponse filter(@Nonnull final AzureFilterThreshold poli
131133 * @return the assistant response object
132134 */
133135 @ Nonnull
134- public OrchestrationChatResponse maskingAnonymization () {
136+ public OrchestrationChatResponse maskingAnonymization (@ Nonnull final DPIEntities entity ) {
135137 final var systemMessage =
136138 Message .system (
137139 "Please evaluate the following user feedback and judge if the sentiment is positive or negative." );
@@ -143,7 +145,7 @@ public OrchestrationChatResponse maskingAnonymization() {
143145 """ );
144146
145147 final var prompt = new OrchestrationPrompt (systemMessage , userMessage );
146- final var maskingConfig = DpiMasking .anonymization ().withEntities (DPIEntities . PERSON );
148+ final var maskingConfig = DpiMasking .anonymization ().withEntities (entity );
147149 final var configWithMasking = config .withMaskingConfig (maskingConfig );
148150
149151 return client .chatCompletion (prompt , configWithMasking );
@@ -156,13 +158,12 @@ public OrchestrationChatResponse maskingAnonymization() {
156158 */
157159 @ Nonnull
158160 public OrchestrationChatResponse completionWithResourceGroup (
159- @ Nonnull final String resourceGroup ) {
160-
161+ @ Nonnull final String resourceGroup , @ Nonnull final String famousPhrase ) {
161162 final var destination =
162163 new AiCoreService ().getInferenceDestination (resourceGroup ).forScenario ("orchestration" );
163164 final var clientWithResourceGroup = new OrchestrationClient (destination );
164165
165- final var prompt = new OrchestrationPrompt ("Hello world! Why is this phrase so famous?" );
166+ final var prompt = new OrchestrationPrompt (famousPhrase + " Why is this phrase so famous?" );
166167
167168 return clientWithResourceGroup .chatCompletion (prompt , config );
168169 }
@@ -177,7 +178,7 @@ public OrchestrationChatResponse completionWithResourceGroup(
177178 * @return the assistant response object
178179 */
179180 @ Nonnull
180- public OrchestrationChatResponse maskingPseudonymization () {
181+ public OrchestrationChatResponse maskingPseudonymization (@ Nonnull final DPIEntities entity ) {
181182 final var systemMessage =
182183 Message .system (
183184 """
@@ -196,8 +197,7 @@ public OrchestrationChatResponse maskingPseudonymization() {
196197 """ );
197198
198199 final var prompt = new OrchestrationPrompt (systemMessage , userMessage );
199- final var maskingConfig =
200- DpiMasking .pseudonymization ().withEntities (DPIEntities .PERSON , DPIEntities .EMAIL );
200+ final var maskingConfig = DpiMasking .pseudonymization ().withEntities (entity , DPIEntities .EMAIL );
201201 final var configWithMasking = config .withMaskingConfig (maskingConfig );
202202
203203 return client .chatCompletion (prompt , configWithMasking );
@@ -211,12 +211,11 @@ public OrchestrationChatResponse maskingPseudonymization() {
211211 * @return the assistant response object
212212 */
213213 @ Nonnull
214- public OrchestrationChatResponse grounding () {
214+ public OrchestrationChatResponse grounding (@ Nonnull final String groundingInput ) {
215215 final var message =
216216 Message .user (
217217 "{{?groundingInput}} Use the following information as additional context: {{?groundingOutput}}" );
218- final var prompt =
219- new OrchestrationPrompt (Map .of ("groundingInput" , "What does Joule do?" ), message );
218+ final var prompt = new OrchestrationPrompt (Map .of ("groundingInput" , groundingInput ), message );
220219
221220 final var filterInner =
222221 DocumentGroundingFilter .create ().id ("someID" ).dataRepositoryType (DataRepositoryType .VECTOR );
@@ -240,9 +239,12 @@ public OrchestrationChatResponse grounding() {
240239 * @return the emitter that streams the assistant message response
241240 */
242241 @ Nonnull
243- public ResponseEntity <ResponseBodyEmitter > streamChatCompletion () {
242+ public ResponseEntity <ResponseBodyEmitter > streamChatCompletion (final int numberOfFibonacci ) {
244243 final var prompt =
245- new OrchestrationPrompt ("Can you give me the first 100 numbers of the Fibonacci sequence?" );
244+ new OrchestrationPrompt (
245+ "Can you give me the first "
246+ + numberOfFibonacci
247+ + " numbers of the Fibonacci sequence?" );
246248 final var stream = client .streamChatCompletion (prompt , config );
247249
248250 final var emitter = new ResponseBodyEmitter ();
0 commit comments