1010import com .sap .ai .sdk .orchestration .Message ;
1111import com .sap .ai .sdk .orchestration .OrchestrationChatResponse ;
1212import com .sap .ai .sdk .orchestration .OrchestrationClient ;
13+ import com .sap .ai .sdk .orchestration .OrchestrationClientException ;
1314import com .sap .ai .sdk .orchestration .OrchestrationModuleConfig ;
1415import com .sap .ai .sdk .orchestration .OrchestrationPrompt ;
1516import com .sap .ai .sdk .orchestration .SystemMessage ;
1920import java .util .List ;
2021import java .util .Map ;
2122import javax .annotation .Nonnull ;
23+ import lombok .extern .slf4j .Slf4j ;
2224import org .springframework .web .bind .annotation .GetMapping ;
2325import org .springframework .web .bind .annotation .PathVariable ;
2426import org .springframework .web .bind .annotation .RequestMapping ;
2527import org .springframework .web .bind .annotation .RestController ;
2628
2729/** Endpoints for the Orchestration service */
2830@ RestController
31+ @ Slf4j
2932@ RequestMapping ("/orchestration" )
3033class OrchestrationController {
3134 private final OrchestrationClient client = new OrchestrationClient ();
@@ -42,7 +45,11 @@ class OrchestrationController {
4245 public OrchestrationChatResponse completion () {
4346 final var prompt = new OrchestrationPrompt ("Hello world! Why is this phrase so famous?" );
4447
45- return client .chatCompletion (prompt , config );
48+ final var result = client .chatCompletion (prompt , config );
49+
50+ log .info ("Our trusty AI answered with: {}" , result .getContent ());
51+
52+ return result ;
4653 }
4754
4855 /**
@@ -106,7 +113,16 @@ public OrchestrationChatResponse filter(
106113 final var configWithFilter =
107114 config .withInputFiltering (filterConfig ).withOutputFiltering (filterConfig );
108115
109- return client .chatCompletion (prompt , configWithFilter );
116+ final OrchestrationChatResponse result = client .chatCompletion (prompt , configWithFilter );
117+ try {
118+ // in case the output was filtered, calling .getContent() will throw
119+ log .info ("The following AI response passed the output filter: {}" , result .getContent ());
120+ } catch (OrchestrationClientException e ) {
121+ log .info ("The content filter blocked the output." );
122+ // alternatively to calling .getContent(), you can also check the finish reason manually
123+ log .info ("Finish reason: {}" , result .getCurrentChoice ().getFinishReason ());
124+ }
125+ return result ;
110126 }
111127
112128 /**
0 commit comments