Skip to content

Commit f184fc7

Browse files
Refactor UnifiedChatCompletionRequestEntity and UnifiedCompletionRequest to rename and update stream options parameter
1 parent 24c52e8 commit f184fc7

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

server/src/main/java/org/elasticsearch/inference/UnifiedCompletionRequest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ public record UnifiedCompletionRequest(
7979
*/
8080
private static final String MAX_TOKENS_PARAM = "max_tokens_field";
8181
/**
82-
* Some providers don't support the stream_options field.
83-
* This parameter is used to skip the stream_options field in the JSON output.
82+
* Indicates whether to include the `stream_options` field in the JSON output.
83+
* Some providers do not support this field. In such cases, this parameter should be set to "false",
84+
* and the `stream_options` field will be excluded from the output.
85+
* For providers that do support stream options, this parameter is left unset (default behavior),
86+
* which implicitly includes the `stream_options` field in the output.
8487
*/
85-
public static final String SKIP_STREAM_OPTIONS_PARAM = "skip_stream_options";
88+
public static final String INCLUDE_STREAM_OPTIONS_PARAM = "include_stream_options";
8689

8790
/**
8891
* Creates a {@link org.elasticsearch.xcontent.ToXContent.Params} that causes ToXContent to include the key values:
@@ -100,14 +103,14 @@ public static Params withMaxTokens(String modelId, Params params) {
100103
* Creates a {@link org.elasticsearch.xcontent.ToXContent.Params} that causes ToXContent to include the key values:
101104
* - Key: {@link #MODEL_FIELD}, Value: modelId
102105
* - Key: {@link #MAX_TOKENS_FIELD}, Value: {@link #MAX_TOKENS_FIELD}
103-
* - Key: {@link #SKIP_STREAM_OPTIONS_PARAM}, Value: "true"
106+
* - Key: {@link #INCLUDE_STREAM_OPTIONS_PARAM}, Value: "false"
104107
*/
105108
public static Params withMaxTokensAndSkipStreamOptionsField(String modelId, Params params) {
106109
return new DelegatingMapParams(
107110
Map.ofEntries(
108111
Map.entry(MODEL_ID_PARAM, modelId),
109112
Map.entry(MAX_TOKENS_PARAM, MAX_TOKENS_FIELD),
110-
Map.entry(SKIP_STREAM_OPTIONS_PARAM, Boolean.TRUE.toString())
113+
Map.entry(INCLUDE_STREAM_OPTIONS_PARAM, Boolean.FALSE.toString())
111114
),
112115
params
113116
);

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/unified/UnifiedChatCompletionRequestEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.io.IOException;
1616
import java.util.Objects;
1717

18-
import static org.elasticsearch.inference.UnifiedCompletionRequest.SKIP_STREAM_OPTIONS_PARAM;
18+
import static org.elasticsearch.inference.UnifiedCompletionRequest.INCLUDE_STREAM_OPTIONS_PARAM;
1919

2020
/**
2121
* Represents a unified chat completion request entity.
@@ -49,7 +49,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
4949

5050
builder.field(STREAM_FIELD, stream);
5151
// If request is streamed and skip stream options parameter is not true, include stream options in the request.
52-
if (stream == true && params.paramAsBoolean(SKIP_STREAM_OPTIONS_PARAM, false) == false) {
52+
if (stream && params.paramAsBoolean(INCLUDE_STREAM_OPTIONS_PARAM, true)) {
5353
builder.startObject(STREAM_OPTIONS_FIELD);
5454
builder.field(INCLUDE_USAGE_FIELD, true);
5555
builder.endObject();

0 commit comments

Comments
 (0)