File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed
orchestration/src/main/java/com/sap/ai/sdk/orchestration
sample-code/spring-app/src
main/java/com/sap/ai/sdk/app/controllers
test/java/com/sap/ai/sdk/app/controllers Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ public class OrchestrationChatResponse {
2929 */
3030 @ Nonnull
3131 public String getContent () throws OrchestrationClientException {
32- final var choice = getCurrentChoice ();
32+ final var choice = getChoice ();
3333
3434 if ("content_filter" .equals (choice .getFinishReason ())) {
3535 throw new OrchestrationClientException ("Content filter filtered the output." );
@@ -67,17 +67,17 @@ public List<Message> getAllMessages() {
6767 messages .add (message );
6868 }
6969
70- messages .add (new AssistantMessage (getCurrentChoice ().getMessage ().getContent ()));
70+ messages .add (new AssistantMessage (getChoice ().getMessage ().getContent ()));
7171 return messages ;
7272 }
7373
7474 /**
75- * Get current choice .
75+ * Get the LLM response. Useful for accessing the finish reason or further data like logprobs .
7676 *
77- * @return The current choice .
77+ * @return The (first, in case of multiple) {@link LLMChoice} .
7878 */
7979 @ Nonnull
80- private LLMChoice getCurrentChoice () {
80+ public LLMChoice getChoice () {
8181 // We expect choices to be defined and never empty.
8282 return ((LLMModuleResultSynchronous ) originalResponse .getOrchestrationResult ())
8383 .getChoices ()
Original file line number Diff line number Diff line change 1616import java .util .List ;
1717import java .util .Map ;
1818import javax .annotation .Nonnull ;
19+ import lombok .extern .slf4j .Slf4j ;
1920import org .springframework .web .bind .annotation .GetMapping ;
2021import org .springframework .web .bind .annotation .PathVariable ;
2122import org .springframework .web .bind .annotation .RequestMapping ;
2223import org .springframework .web .bind .annotation .RestController ;
2324
2425/** Endpoints for the Orchestration service */
2526@ RestController
27+ @ Slf4j
2628@ RequestMapping ("/orchestration" )
2729class OrchestrationController {
2830 private final OrchestrationClient client = new OrchestrationClient ();
@@ -39,7 +41,11 @@ class OrchestrationController {
3941 OrchestrationChatResponse completion () {
4042 final var prompt = new OrchestrationPrompt ("Hello world! Why is this phrase so famous?" );
4143
42- return client .chatCompletion (prompt , config );
44+ final var result = client .chatCompletion (prompt , config );
45+
46+ log .info ("Our trusty AI answered with: {}" , result .getContent ());
47+
48+ return result ;
4349 }
4450
4551 /**
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ void testTemplate() {
6767 assertThat (choices .get (0 ).getMessage ().getContent ()).isNotEmpty ();
6868 assertThat (choices .get (0 ).getMessage ().getRole ()).isEqualTo ("assistant" );
6969 assertThat (choices .get (0 ).getFinishReason ()).isEqualTo ("stop" );
70+ assertThat (result .getChoice ()).isSameAs (choices .get (0 ));
7071 usage = result .getTokenUsage ();
7172 assertThat (usage .getCompletionTokens ()).isGreaterThan (1 );
7273 assertThat (usage .getPromptTokens ()).isGreaterThan (1 );
You can’t perform that action at this time.
0 commit comments