11package com .sap .ai .sdk .foundationmodels .openai ;
22
33import com .fasterxml .jackson .annotation .JsonCreator ;
4- import com .fasterxml .jackson .annotation .JsonIgnore ;
5- import com .fasterxml .jackson .annotation .JsonValue ;
4+ import com .google .common .annotations .Beta ;
65import com .sap .ai .sdk .core .common .StreamedDelta ;
76import com .sap .ai .sdk .foundationmodels .openai .model2 .ChatCompletionsCreate200Response ;
87import com .sap .ai .sdk .foundationmodels .openai .model2 .CreateChatCompletionResponse ;
98import com .sap .ai .sdk .foundationmodels .openai .model2 .CreateChatCompletionStreamResponse ;
10- import com .sap .ai .sdk .foundationmodels .openai .model2 .CreateChatCompletionStreamResponseChoicesInner ;
11- import lombok .AccessLevel ;
12- import lombok .RequiredArgsConstructor ;
13- import lombok .Value ;
14-
15- import java .util .List ;
169import java .util .Objects ;
1710import javax .annotation .Nonnull ;
1811import javax .annotation .Nullable ;
12+ import lombok .RequiredArgsConstructor ;
13+ import lombok .Value ;
1914
20-
15+ /**
16+ * OpenAI chat completion output delta for streaming.
17+ *
18+ * @since 1.3.0
19+ */
20+ @ Beta
2121@ Value
2222@ RequiredArgsConstructor (onConstructor_ = @ JsonCreator )
2323public class OpenAiChatCompletionDelta implements StreamedDelta {
@@ -26,7 +26,7 @@ public class OpenAiChatCompletionDelta implements StreamedDelta {
2626 @ Nonnull
2727 @ Override
2828 public String getDeltaContent () {
29- if ( getOriginalResponse () instanceof CreateChatCompletionStreamResponse response ) {
29+ if ( getOriginalResponse () instanceof CreateChatCompletionStreamResponse response ) {
3030 final var choices = response .getChoices ();
3131 if (!choices .isEmpty () && choices .get (0 ).getIndex () == 0 ) {
3232 final var message = choices .get (0 ).getDelta ();
@@ -35,7 +35,7 @@ public String getDeltaContent() {
3535 }
3636 }
3737 }
38- if ( getOriginalResponse () instanceof CreateChatCompletionResponse response ) {
38+ if ( getOriginalResponse () instanceof CreateChatCompletionResponse response ) {
3939 final var choices = response .getChoices ();
4040 if (!choices .isEmpty () && choices .get (0 ).getIndex () == 0 ) {
4141 final var delta = choices .get (0 ).getCustomField ("delta" ); // .getMessage() does not work
@@ -50,14 +50,14 @@ public String getDeltaContent() {
5050 @ Nullable
5151 @ Override
5252 public String getFinishReason () {
53- if ( getOriginalResponse () instanceof CreateChatCompletionStreamResponse response ) {
53+ if ( getOriginalResponse () instanceof CreateChatCompletionStreamResponse response ) {
5454 final var choices = response .getChoices ();
5555 if (!choices .isEmpty ()) {
5656 final var finishReason = choices .get (0 ).getFinishReason ();
5757 return finishReason != null ? finishReason .getValue () : null ;
5858 }
5959 }
60- if ( getOriginalResponse () instanceof CreateChatCompletionResponse response ) {
60+ if ( getOriginalResponse () instanceof CreateChatCompletionResponse response ) {
6161 final var choices = response .getChoices ();
6262 if (!choices .isEmpty ()) {
6363 final var finishReason = choices .get (0 ).getFinishReason ();
0 commit comments