|
1 | 1 | package com.sap.ai.sdk.orchestration.spring; |
2 | 2 |
|
3 | | -import com.google.common.annotations.Beta; |
4 | | -import com.sap.ai.sdk.orchestration.model.CompletionPostResponse; |
| 3 | +import com.sap.ai.sdk.orchestration.OrchestrationChatResponse; |
5 | 4 | import com.sap.ai.sdk.orchestration.model.LLMChoice; |
6 | 5 | import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous; |
7 | 6 | import com.sap.ai.sdk.orchestration.model.TokenUsage; |
|
18 | 17 | import org.springframework.ai.chat.model.ChatResponse; |
19 | 18 | import org.springframework.ai.chat.model.Generation; |
20 | 19 |
|
21 | | -/** |
22 | | - * Response from the orchestration service in a Spring AI {@link ChatResponse}. |
23 | | - * |
24 | | - * @since 1.2.0 |
25 | | - */ |
26 | | -@Beta |
| 20 | +/** Response from the orchestration service in a Spring AI {@link ChatResponse}. */ |
27 | 21 | @Value |
28 | 22 | @EqualsAndHashCode(callSuper = true) |
29 | | -public class OrchestrationChatResponse extends ChatResponse { |
| 23 | +class OrchestrationSpringChatResponse extends ChatResponse { |
30 | 24 |
|
31 | | - private OrchestrationChatResponse( |
32 | | - @Nonnull final List<Generation> generations, @Nonnull final ChatResponseMetadata metadata) { |
33 | | - super(generations, metadata); |
34 | | - } |
| 25 | + OrchestrationChatResponse response; |
35 | 26 |
|
36 | | - @Nonnull |
37 | | - static OrchestrationChatResponse fromOrchestrationResponse( |
38 | | - @Nonnull final CompletionPostResponse response) { |
39 | | - val result = (LLMModuleResultSynchronous) response.getOrchestrationResult(); |
40 | | - val generations = toGenerations(result); |
41 | | - val metadata = toChatResponseMetadata(result); |
42 | | - return new OrchestrationChatResponse(generations, metadata); |
| 27 | + OrchestrationSpringChatResponse(@Nonnull final OrchestrationChatResponse response) { |
| 28 | + super( |
| 29 | + toGenerations( |
| 30 | + (LLMModuleResultSynchronous) response.getOriginalResponse().getOrchestrationResult()), |
| 31 | + toChatResponseMetadata( |
| 32 | + (LLMModuleResultSynchronous) response.getOriginalResponse().getOrchestrationResult())); |
| 33 | + this.response = response; |
43 | 34 | } |
44 | 35 |
|
45 | 36 | @Nonnull |
46 | 37 | static List<Generation> toGenerations(@Nonnull final LLMModuleResultSynchronous result) { |
47 | 38 | return result.getChoices().stream() |
48 | | - .map(OrchestrationChatResponse::toAssistantMessage) |
| 39 | + .map(OrchestrationSpringChatResponse::toAssistantMessage) |
49 | 40 | .map(Generation::new) |
50 | 41 | .toList(); |
51 | 42 | } |
|
0 commit comments