Skip to content

Commit ec15a5a

Browse files
committed
Apply requested changes
1 parent bb8141e commit ec15a5a

File tree

3 files changed

+18
-62
lines changed

3 files changed

+18
-62
lines changed

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationChatResponse.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.sap.ai.sdk.orchestration.client.model.ChatMessage;
66
import com.sap.ai.sdk.orchestration.client.model.CompletionPostResponse;
7+
import com.sap.ai.sdk.orchestration.client.model.LLMChoice;
78
import com.sap.ai.sdk.orchestration.client.model.LLMModuleResultSynchronous;
89
import com.sap.ai.sdk.orchestration.client.model.TokenUsage;
910
import 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
}

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,4 @@ void testErrorHandling() {
413413

414414
softly.assertAll();
415415
}
416-
417-
@Test
418-
void testEmptyChoicesResponse() {
419-
stubFor(
420-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
421-
.willReturn(
422-
aResponse()
423-
.withBodyFile("emptyChoicesResponse.json")
424-
.withHeader("Content-Type", "application/json")));
425-
final var result = client.chatCompletion(prompt, config);
426-
427-
assertThat(result.getContent()).isEmpty();
428-
}
429416
}

orchestration/src/test/resources/__files/emptyChoicesResponse.json

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)