OpenAI: Fix model property being overwritten by default value
Fixes gh-671 Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit is contained in:
committed by
Christian Tzolov
parent
f91ccf0047
commit
1c93ae50a8
@@ -19,7 +19,6 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.springframework.ai.image.ImageOptions;
|
||||
import org.springframework.ai.openai.api.OpenAiImageApi;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -44,7 +43,7 @@ public class OpenAiImageOptions implements ImageOptions {
|
||||
* The model to use for image generation.
|
||||
*/
|
||||
@JsonProperty("model")
|
||||
private String model = OpenAiImageApi.DEFAULT_IMAGE_MODEL;
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* The width of the generated images. Must be one of 256, 512, or 1024 for dall-e-2.
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.ai.autoconfigure.openai;
|
||||
|
||||
import org.springframework.ai.openai.OpenAiImageOptions;
|
||||
import org.springframework.ai.openai.api.OpenAiImageApi;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
|
||||
@@ -30,6 +31,8 @@ public class OpenAiImageProperties extends OpenAiParentProperties {
|
||||
|
||||
public static final String CONFIG_PREFIX = "spring.ai.openai.image";
|
||||
|
||||
public static final String DEFAULT_IMAGE_MODEL = OpenAiImageApi.ImageModel.DALL_E_3.getValue();
|
||||
|
||||
/**
|
||||
* Enable OpenAI Image client.
|
||||
*/
|
||||
@@ -39,7 +42,7 @@ public class OpenAiImageProperties extends OpenAiParentProperties {
|
||||
* Options for OpenAI Image API.
|
||||
*/
|
||||
@NestedConfigurationProperty
|
||||
private OpenAiImageOptions options = OpenAiImageOptions.builder().build();
|
||||
private OpenAiImageOptions options = OpenAiImageOptions.builder().withModel(DEFAULT_IMAGE_MODEL).build();
|
||||
|
||||
public OpenAiImageOptions getOptions() {
|
||||
return options;
|
||||
|
||||
@@ -144,4 +144,19 @@ public class OpenAiAutoConfigurationIT {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateImageWithModel() {
|
||||
// The 256x256 size is supported by dall-e-2, but not by dall-e-3.
|
||||
contextRunner
|
||||
.withPropertyValues("spring.ai.openai.image.options.model=dall-e-2",
|
||||
"spring.ai.openai.image.options.size=256x256")
|
||||
.run(context -> {
|
||||
OpenAiImageClient client = context.getBean(OpenAiImageClient.class);
|
||||
ImageResponse imageResponse = client.call(new ImagePrompt("forest"));
|
||||
assertThat(imageResponse.getResults()).hasSize(1);
|
||||
assertThat(imageResponse.getResult().getOutput().getUrl()).isNotEmpty();
|
||||
logger.info("Generated image: " + imageResponse.getResult().getOutput().getUrl());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user