Refactor ImageOptions builder method

- Deprecate the builder method with the prefix 'with' and add new methods
This commit is contained in:
Ilayaperumal Gopinathan
2024-12-17 01:45:32 +00:00
committed by Mark Pollack
parent 18bc0cff25
commit 627fb79e5e
8 changed files with 71 additions and 17 deletions

View File

@@ -53,7 +53,7 @@ public class AzureOpenAiImageModelIT {
@Test
void imageAsUrlTest() {
var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build();
var options = ImageOptionsBuilder.builder().height(1024).width(1024).build();
var instructions = """
A light cream colored mini golden doodle with a sign that contains the message "I'm on my way to BARCADE!".""";

View File

@@ -38,7 +38,7 @@ public class OpenAiImageModelIT extends AbstractIT {
@Test
void imageAsUrlTest() {
var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build();
var options = ImageOptionsBuilder.builder().height(1024).width(1024).build();
var instructions = """
A light cream colored mini golden doodle with a sign that contains the message "I'm on my way to BARCADE!".""";

View File

@@ -45,7 +45,7 @@ public class QianFanImageModelIT {
@Test
void imageTest() {
var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build();
var options = ImageOptionsBuilder.builder().height(1024).width(1024).build();
var instructions = """
A light cream colored mini golden doodle with a sign that contains the message "I'm on my way to BARCADE!".""";

View File

@@ -40,7 +40,7 @@ public class ZhiPuAiImageModelIT {
@Test
void imageAsUrlTest() {
var options = ImageOptionsBuilder.builder().withHeight(1024).withWidth(1024).build();
var options = ImageOptionsBuilder.builder().height(1024).width(1024).build();
var instructions = """
A light cream colored mini golden doodle with a sign that contains the message "I'm on my way to BARCADE!".""";

View File

@@ -28,31 +28,85 @@ public final class ImageOptionsBuilder {
return new ImageOptionsBuilder();
}
public ImageOptionsBuilder N(Integer n) {
this.options.setN(n);
return this;
}
public ImageOptionsBuilder model(String model) {
this.options.setModel(model);
return this;
}
public ImageOptionsBuilder responseFormat(String responseFormat) {
this.options.setResponseFormat(responseFormat);
return this;
}
public ImageOptionsBuilder width(Integer width) {
this.options.setWidth(width);
return this;
}
public ImageOptionsBuilder height(Integer height) {
this.options.setHeight(height);
return this;
}
public ImageOptionsBuilder style(String style) {
this.options.setStyle(style);
return this;
}
/**
* @deprecated use {@link #N(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public ImageOptionsBuilder withN(Integer n) {
this.options.setN(n);
return this;
}
/**
* @deprecated use {@link #model(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public ImageOptionsBuilder withModel(String model) {
this.options.setModel(model);
return this;
}
/**
* @deprecated use {@link #responseFormat(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public ImageOptionsBuilder withResponseFormat(String responseFormat) {
this.options.setResponseFormat(responseFormat);
return this;
}
/**
* @deprecated use {@link #width(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public ImageOptionsBuilder withWidth(Integer width) {
this.options.setWidth(width);
return this;
}
/**
* @deprecated use {@link #height(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public ImageOptionsBuilder withHeight(Integer height) {
this.options.setHeight(height);
return this;
}
/**
* @deprecated use {@link #style(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public ImageOptionsBuilder withStyle(String style) {
this.options.setStyle(style);
return this;

View File

@@ -46,7 +46,7 @@ class DefaultImageModelObservationConventionTests {
ImageModelObservationContext observationContext = ImageModelObservationContext.builder()
.imagePrompt(generateImagePrompt())
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("mistral").build())
.requestOptions(ImageOptionsBuilder.builder().model("mistral").build())
.build();
assertThat(this.observationConvention.getContextualName(observationContext)).isEqualTo("image mistral");
}
@@ -66,7 +66,7 @@ class DefaultImageModelObservationConventionTests {
ImageModelObservationContext observationContext = ImageModelObservationContext.builder()
.imagePrompt(generateImagePrompt())
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("mistral").build())
.requestOptions(ImageOptionsBuilder.builder().model("mistral").build())
.build();
assertThat(this.observationConvention.supportsContext(observationContext)).isTrue();
assertThat(this.observationConvention.supportsContext(new Observation.Context())).isFalse();
@@ -77,7 +77,7 @@ class DefaultImageModelObservationConventionTests {
ImageModelObservationContext observationContext = ImageModelObservationContext.builder()
.imagePrompt(generateImagePrompt())
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("mistral").build())
.requestOptions(ImageOptionsBuilder.builder().model("mistral").build())
.build();
assertThat(this.observationConvention.getLowCardinalityKeyValues(observationContext)).contains(
KeyValue.of(AiObservationAttributes.AI_OPERATION_TYPE.value(), "image"),
@@ -91,12 +91,12 @@ class DefaultImageModelObservationConventionTests {
.imagePrompt(generateImagePrompt())
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder()
.withModel("mistral")
.withN(1)
.withHeight(1080)
.withWidth(1920)
.withStyle("sketch")
.withResponseFormat("base64")
.model("mistral")
.N(1)
.height(1080)
.width(1920)
.style("sketch")
.responseFormat("base64")
.build())
.build();

View File

@@ -36,7 +36,7 @@ class ImageModelObservationContextTests {
var observationContext = ImageModelObservationContext.builder()
.imagePrompt(generateImagePrompt())
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("supersun").build())
.requestOptions(ImageOptionsBuilder.builder().model("supersun").build())
.build();
assertThat(observationContext).isNotNull();

View File

@@ -51,7 +51,7 @@ class ImageModelPromptContentObservationFilterTests {
var expectedContext = ImageModelObservationContext.builder()
.imagePrompt(new ImagePrompt(""))
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("mistral").build())
.requestOptions(ImageOptionsBuilder.builder().model("mistral").build())
.build();
var actualContext = this.observationFilter.map(expectedContext);
@@ -63,7 +63,7 @@ class ImageModelPromptContentObservationFilterTests {
var originalContext = ImageModelObservationContext.builder()
.imagePrompt(new ImagePrompt("supercalifragilisticexpialidocious"))
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("mistral").build())
.requestOptions(ImageOptionsBuilder.builder().model("mistral").build())
.build();
var augmentedContext = this.observationFilter.map(originalContext);
@@ -77,7 +77,7 @@ class ImageModelPromptContentObservationFilterTests {
.imagePrompt(new ImagePrompt(List.of(new ImageMessage("you're a chimney sweep"),
new ImageMessage("supercalifragilisticexpialidocious"))))
.provider("superprovider")
.requestOptions(ImageOptionsBuilder.builder().withModel("mistral").build())
.requestOptions(ImageOptionsBuilder.builder().model("mistral").build())
.build();
var augmentedContext = this.observationFilter.map(originalContext);