|
24 | 24 | import java.util.List;
|
25 | 25 | import java.util.Objects;
|
26 | 26 |
|
| 27 | +import org.opensearch.Version; |
27 | 28 | import org.opensearch.core.common.Strings;
|
28 | 29 | import org.opensearch.core.common.io.stream.StreamInput;
|
29 | 30 | import org.opensearch.core.common.io.stream.StreamOutput;
|
30 | 31 | import org.opensearch.core.common.io.stream.Writeable;
|
31 | 32 | import org.opensearch.core.xcontent.ToXContentObject;
|
32 | 33 | import org.opensearch.core.xcontent.XContentBuilder;
|
33 | 34 | import org.opensearch.core.xcontent.XContentParser;
|
| 35 | +import org.opensearch.ml.common.CommonValue; |
34 | 36 | import org.opensearch.searchpipelines.questionanswering.generative.llm.MessageBlock;
|
35 | 37 |
|
36 | 38 | import com.google.common.base.Preconditions;
|
@@ -86,6 +88,8 @@ public class GenerativeQAParameters implements Writeable, ToXContentObject {
|
86 | 88 |
|
87 | 89 | public static final int SIZE_NULL_VALUE = -1;
|
88 | 90 |
|
| 91 | + static final Version MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES = CommonValue.VERSION_2_18_0; |
| 92 | + |
89 | 93 | @Setter
|
90 | 94 | @Getter
|
91 | 95 | private String conversationId;
|
@@ -185,16 +189,27 @@ public GenerativeQAParameters(
|
185 | 189 | }
|
186 | 190 |
|
187 | 191 | public GenerativeQAParameters(StreamInput input) throws IOException {
|
| 192 | + Version version = input.getVersion(); |
188 | 193 | this.conversationId = input.readOptionalString();
|
189 | 194 | this.llmModel = input.readOptionalString();
|
190 |
| - this.llmQuestion = input.readOptionalString(); |
| 195 | + |
| 196 | + // this string was made optional in 2.18 |
| 197 | + if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)) { |
| 198 | + this.llmQuestion = input.readOptionalString(); |
| 199 | + } else { |
| 200 | + this.llmQuestion = input.readString(); |
| 201 | + } |
| 202 | + |
191 | 203 | this.systemPrompt = input.readOptionalString();
|
192 | 204 | this.userInstructions = input.readOptionalString();
|
193 | 205 | this.contextSize = input.readInt();
|
194 | 206 | this.interactionSize = input.readInt();
|
195 | 207 | this.timeout = input.readInt();
|
196 | 208 | this.llmResponseField = input.readOptionalString();
|
197 |
| - this.llmMessages.addAll(input.readList(MessageBlock::new)); |
| 209 | + |
| 210 | + if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)) { |
| 211 | + this.llmMessages.addAll(input.readList(MessageBlock::new)); |
| 212 | + } |
198 | 213 | }
|
199 | 214 |
|
200 | 215 | @Override
|
@@ -246,16 +261,27 @@ public XContentBuilder toXContent(XContentBuilder xContentBuilder, Params params
|
246 | 261 |
|
247 | 262 | @Override
|
248 | 263 | public void writeTo(StreamOutput out) throws IOException {
|
| 264 | + Version version = out.getVersion(); |
249 | 265 | out.writeOptionalString(conversationId);
|
250 | 266 | out.writeOptionalString(llmModel);
|
251 |
| - out.writeOptionalString(llmQuestion); |
| 267 | + |
| 268 | + // this string was made optional in 2.18 |
| 269 | + if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)) { |
| 270 | + out.writeOptionalString(llmQuestion); |
| 271 | + } else { |
| 272 | + out.writeString(llmQuestion); |
| 273 | + } |
| 274 | + |
252 | 275 | out.writeOptionalString(systemPrompt);
|
253 | 276 | out.writeOptionalString(userInstructions);
|
254 | 277 | out.writeInt(contextSize);
|
255 | 278 | out.writeInt(interactionSize);
|
256 | 279 | out.writeInt(timeout);
|
257 | 280 | out.writeOptionalString(llmResponseField);
|
258 |
| - out.writeList(llmMessages); |
| 281 | + |
| 282 | + if (version.onOrAfter(MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)) { |
| 283 | + out.writeList(llmMessages); |
| 284 | + } |
259 | 285 | }
|
260 | 286 |
|
261 | 287 | public static GenerativeQAParameters parse(XContentParser parser) throws IOException {
|
|
0 commit comments