99import com .sap .ai .sdk .orchestration .spring .OrchestrationChatModel ;
1010import com .sap .ai .sdk .orchestration .spring .OrchestrationChatOptions ;
1111import java .util .Map ;
12+ import lombok .val ;
1213import org .springframework .ai .chat .client .ChatClient ;
1314import org .springframework .ai .chat .client .advisor .MessageChatMemoryAdvisor ;
1415import org .springframework .ai .chat .memory .InMemoryChatMemory ;
2324/** Endpoints for the Orchestration service */
2425@ RestController
2526@ RequestMapping ("/orchestration" )
26- class OrchestrationController {
27+ class SpringAiOrchestrationController {
2728
28- ChatModel client = new OrchestrationChatModel (new OrchestrationClient ());
29+ private final ChatModel client = new OrchestrationChatModel (new OrchestrationClient ());
2930 private final OrchestrationModuleConfig config =
3031 new OrchestrationModuleConfig ().withLlmConfig (GPT_35_TURBO );
3132 private final OrchestrationChatOptions defaultOptions = new OrchestrationChatOptions (config );
3233
3334 @ GetMapping ("/completion" )
3435 ChatResponse completion () {
35- var prompt = new Prompt ("What is the capital of France?" , defaultOptions );
36+ val prompt = new Prompt ("What is the capital of France?" , defaultOptions );
3637
3738 return client .call (prompt );
3839 }
3940
4041 @ GetMapping ("/template" )
4142 ChatResponse template () {
42- var template = new PromptTemplate ("{input}" );
43- var prompt = template .create (Map .of ("input" , "Hello World!" ), defaultOptions );
43+ val template = new PromptTemplate ("{input}" );
44+ val prompt = template .create (Map .of ("input" , "Hello World!" ), defaultOptions );
4445
4546 return client .call (prompt );
4647 }
4748
4849 @ GetMapping ("/masking" )
4950 ChatResponse masking () {
50- var masking =
51+ val masking =
5152 DpiMasking .anonymization ()
5253 .withEntities (DPIEntities .EMAIL , DPIEntities .ADDRESS , DPIEntities .LOCATION );
5354
54- var opts = new OrchestrationChatOptions (config .withMaskingConfig (masking ));
55- var prompt =
55+ val opts = new OrchestrationChatOptions (config .withMaskingConfig (masking ));
56+ val prompt =
5657 new Prompt (
5758 "Please write 'Hello World!' to me via email. My email address is [email protected] " ,
5859 opts );
@@ -62,11 +63,11 @@ ChatResponse masking() {
6263
6364 @ GetMapping ("/chatMemory" )
6465 ChatResponse chatMemory () {
65- var memory = new InMemoryChatMemory ();
66- var advisor = new MessageChatMemoryAdvisor (memory );
67- ChatClient cl = ChatClient .builder (client ).defaultAdvisors (advisor ).build ();
68- var prompt1 = new Prompt ("What is the capital of France?" , defaultOptions );
69- var prompt2 = new Prompt ("And what is the typical food there?" , defaultOptions );
66+ val memory = new InMemoryChatMemory ();
67+ val advisor = new MessageChatMemoryAdvisor (memory );
68+ val cl = ChatClient .builder (client ).defaultAdvisors (advisor ).build ();
69+ val prompt1 = new Prompt ("What is the capital of France?" , defaultOptions );
70+ val prompt2 = new Prompt ("And what is the typical food there?" , defaultOptions );
7071
7172 cl .prompt (prompt1 ).call ();
7273 return cl .prompt (prompt2 ).call ().chatResponse ();
0 commit comments