44
55import com .sap .ai .sdk .orchestration .client .model .ChatMessage ;
66import com .sap .ai .sdk .orchestration .client .model .CompletionPostResponse ;
7+ import com .sap .ai .sdk .orchestration .client .model .LLMChoice ;
78import com .sap .ai .sdk .orchestration .client .model .LLMModuleResultSynchronous ;
89import com .sap .ai .sdk .orchestration .client .model .TokenUsage ;
910import java .util .List ;
@@ -27,14 +28,7 @@ public class OrchestrationChatResponse {
2728 */
2829 @ Nonnull
2930 public String getContent () throws OrchestrationClientException {
30- final var choices =
31- ((LLMModuleResultSynchronous ) originalResponse .getOrchestrationResult ()).getChoices ();
32-
33- if (choices .isEmpty ()) {
34- return "" ;
35- }
36-
37- final var choice = choices .get (0 );
31+ final var choice = getCurrentChoice ();
3832
3933 if ("content_filter" .equals (choice .getFinishReason ())) {
4034 throw new OrchestrationClientException ("Content filter filtered the output." );
@@ -53,17 +47,27 @@ public TokenUsage getTokenUsage() {
5347 }
5448
5549 /**
56- * Get all messages.
50+ * Get all messages. This can be used for subsequent prompts as a message history.
5751 *
5852 * @return A list of all messages.
5953 */
6054 @ Nonnull
6155 public List <ChatMessage > getAllMessages () {
62- final var allMessages = originalResponse .getModuleResults ().getTemplating ();
56+ final var messages = originalResponse .getModuleResults ().getTemplating ();
6357
64- if (allMessages == null ) {
65- return List .of ();
66- }
67- return allMessages ;
58+ messages .add (getCurrentChoice ().getMessage ());
59+ return messages ;
60+ }
61+
62+ /**
63+ * Get list of choices.
64+ *
65+ * @return A list of choices.
66+ */
67+ @ Nonnull
68+ private LLMChoice getCurrentChoice () {
69+ return ((LLMModuleResultSynchronous ) originalResponse .getOrchestrationResult ())
70+ .getChoices ()
71+ .get (0 );
6872 }
6973}
0 commit comments