Various, minor Amazon Bedrock ITs improvements

This commit is contained in:
Christian Tzolov
2024-05-26 19:40:00 +02:00
parent a4e3a7b8de
commit a49974d90f
6 changed files with 10 additions and 9 deletions

View File

@@ -217,6 +217,7 @@ public class AnthropicChatBedrockApi extends
*/
@JsonInclude(Include.NON_NULL)
public record AnthropicChatResponse(
@JsonProperty("type") String type,
@JsonProperty("completion") String completion,
@JsonProperty("stop_reason") String stopReason,
@JsonProperty("stop") String stop,

View File

@@ -239,7 +239,7 @@ public abstract class AbstractBedrockApi<I, O, SO> {
SdkBytes body;
try {
body = SdkBytes.fromUtf8String(new ObjectMapper().writeValueAsString(request));
body = SdkBytes.fromUtf8String(this.objectMapper.writeValueAsString(request));
}
catch (JsonProcessingException e) {
throw new IllegalArgumentException("Invalid JSON format for the input request: " + request, e);

View File

@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Christian Tzolov
*/
public class BedrockTitanChatCreateRequestTests {
public class BedrockTitanChatModelCreateRequestTests {
private TitanChatBedrockApi api = new TitanChatBedrockApi(TitanChatModel.TITAN_TEXT_EXPRESS_V1.id(),
EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), new ObjectMapper(),
@@ -41,7 +41,7 @@ public class BedrockTitanChatCreateRequestTests {
@Test
public void createRequestWithChatOptions() {
var client = new BedrockTitanChatModel(api,
var model = new BedrockTitanChatModel(api,
BedrockTitanChatOptions.builder()
.withTemperature(66.6f)
.withTopP(0.66f)
@@ -49,7 +49,7 @@ public class BedrockTitanChatCreateRequestTests {
.withStopSequences(List.of("stop1", "stop2"))
.build());
var request = client.createRequest(new Prompt("Test message content"));
var request = model.createRequest(new Prompt("Test message content"));
assertThat(request.inputText()).isNotEmpty();
assertThat(request.textGenerationConfig().temperature()).isEqualTo(66.6f);
@@ -57,7 +57,7 @@ public class BedrockTitanChatCreateRequestTests {
assertThat(request.textGenerationConfig().maxTokenCount()).isEqualTo(666);
assertThat(request.textGenerationConfig().stopSequences()).containsExactly("stop1", "stop2");
request = client.createRequest(new Prompt("Test message content",
request = model.createRequest(new Prompt("Test message content",
BedrockTitanChatOptions.builder()
.withTemperature(99.9f)
.withTopP(0.99f)

View File

@@ -55,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
@EnabledIfEnvironmentVariable(named = "AWS_ACCESS_KEY_ID", matches = ".*")
@EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*")
class BedrockTitanModelCalerlIT {
class BedrockTitanChatModelIT {
@Autowired
private BedrockTitanChatModel chatModel;
@@ -103,7 +103,7 @@ class BedrockTitanModelCalerlIT {
assertThat(response.getResult().getOutput().getContent()).contains("Blackbeard");
}
@Disabled("TODO: Fix the parser instructions to return the correct format")
// @Disabled("TODO: Fix the parser instructions to return the correct format")
@Test
void listOutputConverter() {
DefaultConversionService conversionService = new DefaultConversionService();
@@ -123,7 +123,7 @@ class BedrockTitanModelCalerlIT {
assertThat(list).hasSize(5);
}
@Disabled("TODO: Fix the parser instructions to return the correct format")
// @Disabled("TODO: Fix the parser instructions to return the correct format")
@Test
void mapOutputConverter() {
MapOutputConverter outputConverter = new MapOutputConverter();

View File

@@ -63,7 +63,7 @@ public class TitanEmbeddingBedrockApiIT {
TitanEmbeddingBedrockApi titanEmbedApi = new TitanEmbeddingBedrockApi(
TitanEmbeddingModel.TITAN_EMBED_TEXT_V2.id(), EnvironmentVariableCredentialsProvider.create(),
Region.US_WEST_2.id(), new ObjectMapper(), Duration.ofMinutes(2));
Region.US_EAST_1.id(), new ObjectMapper(), Duration.ofMinutes(2));
TitanEmbeddingRequest request = TitanEmbeddingRequest.builder().withInputText("I like to eat apples.").build();