Skip to content

Commit

Permalink
test: adding ut for bwc
Browse files Browse the repository at this point in the history
Signed-off-by: Pavan Yekbote <[email protected]>
  • Loading branch information
pyek-bot committed Oct 28, 2024
1 parent c3d5673 commit 9029ae5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class GenerativeQAParameters implements Writeable, ToXContentObject {

public static final int SIZE_NULL_VALUE = -1;

private static final Version MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES = CommonValue.VERSION_2_18_0;
static final Version MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES = CommonValue.VERSION_2_18_0;

@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import java.util.List;
import java.util.Map;

import org.opensearch.Version;
import org.opensearch.action.search.SearchRequest;
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.XContent;
import org.opensearch.core.xcontent.XContentBuilder;
Expand Down Expand Up @@ -179,6 +182,48 @@ public void testWriteTo() throws IOException {
assertTrue(timeout == intValues.get(2));
}

public void testWriteToBwcBedrockConverse() throws IOException {
String conversationId = "a";
String llmModel = "b";
String llmQuestion = "c";
String systemPrompt = "s";
String userInstructions = "u";
int contextSize = 1;
int interactionSize = 2;
int timeout = 10;
String llmResponseField = "text";
GenerativeQAParameters expected = new GenerativeQAParameters(
conversationId,
llmModel,
llmQuestion,
systemPrompt,
userInstructions,
contextSize,
interactionSize,
timeout,
llmResponseField,
messageList
);

// Version.2_18_0 (MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES)
BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(GenerativeQAParameters.MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES);
expected.writeTo(output);
StreamInput input = output.bytes().streamInput();
input.setVersion(GenerativeQAParameters.MINIMAL_SUPPORTED_VERSION_FOR_BEDROCK_CONVERSE_LLM_MESSAGES);
GenerativeQAParameters actual = new GenerativeQAParameters(input);
assertEquals(expected, actual);

// Version.2_17_0 (LlmMessages should be empty list)
output = new BytesStreamOutput();
output.setVersion(Version.V_2_17_0);
expected.writeTo(output);
input = output.bytes().streamInput();
input.setVersion(Version.V_2_17_0);
actual = new GenerativeQAParameters(input);
assertTrue(actual.getLlmMessages().isEmpty());
}

public void testMisc() {
String conversationId = "a";
String llmModel = "b";
Expand Down

0 comments on commit 9029ae5

Please sign in to comment.