Revert "Add default ChatOptions to Prompt"
This reverts commit4eeeb83d3f. Revert "Make ImageOptions non-null when constructing ImagePrompt" This reverts commit0c0787b849. Need to review more the impact of making these options not null. Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
This commit is contained in:
committed by
Mark Pollack
parent
af0303f65a
commit
ec95eeb250
@@ -34,6 +34,7 @@ import org.springframework.ai.audio.transcription.AudioTranscriptionResponse;
|
||||
import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.ai.document.MetadataMode;
|
||||
import org.springframework.ai.image.ImageMessage;
|
||||
import org.springframework.ai.image.ImageOptionsBuilder;
|
||||
import org.springframework.ai.image.ImagePrompt;
|
||||
import org.springframework.ai.openai.OpenAiAudioTranscriptionModel;
|
||||
import org.springframework.ai.openai.OpenAiAudioTranscriptionOptions;
|
||||
@@ -250,7 +251,8 @@ public class OpenAiRetryTests {
|
||||
.willThrow(new TransientAiException("Transient Error 2"))
|
||||
.willReturn(ResponseEntity.of(Optional.of(expectedResponse)));
|
||||
|
||||
var result = this.imageModel.call(new ImagePrompt(List.of(new ImageMessage("Image Message"))));
|
||||
var result = this.imageModel
|
||||
.call(new ImagePrompt(List.of(new ImageMessage("Image Message")), ImageOptionsBuilder.builder().build()));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getResult().getOutput().getUrl()).isEqualTo("url678");
|
||||
@@ -262,8 +264,8 @@ public class OpenAiRetryTests {
|
||||
public void openAiImageNonTransientError() {
|
||||
given(this.openAiImageApi.createImage(isA(OpenAiImageRequest.class)))
|
||||
.willThrow(new RuntimeException("Transient Error 1"));
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> this.imageModel.call(new ImagePrompt(List.of(new ImageMessage("Image Message")))));
|
||||
assertThrows(RuntimeException.class, () -> this.imageModel
|
||||
.call(new ImagePrompt(List.of(new ImageMessage("Image Message")), ImageOptionsBuilder.builder().build())));
|
||||
}
|
||||
|
||||
private static class TestRetryListener implements RetryListener {
|
||||
|
||||
@@ -110,8 +110,7 @@ class DefaultChatClientTests {
|
||||
assertThat(spec.getMessages()).hasSize(2);
|
||||
assertThat(spec.getMessages().get(0).getText()).isEqualTo("instructions");
|
||||
assertThat(spec.getMessages().get(1).getText()).isEqualTo("my question");
|
||||
assertThat(spec.getChatOptions()).isNotNull();
|
||||
assertThat(spec.getChatOptions()).isInstanceOf(ChatOptions.class);
|
||||
assertThat(spec.getChatOptions()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,7 +47,8 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
|
||||
private final List<Message> messages;
|
||||
|
||||
private final ChatOptions chatOptions;
|
||||
@Nullable
|
||||
private ChatOptions chatOptions;
|
||||
|
||||
public Prompt(String contents) {
|
||||
this(new UserMessage(contents));
|
||||
@@ -58,26 +59,26 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
}
|
||||
|
||||
public Prompt(List<Message> messages) {
|
||||
this(messages, ChatOptions.builder().build());
|
||||
this(messages, null);
|
||||
}
|
||||
|
||||
public Prompt(Message... messages) {
|
||||
this(Arrays.asList(messages), ChatOptions.builder().build());
|
||||
this(Arrays.asList(messages), null);
|
||||
}
|
||||
|
||||
public Prompt(String contents, ChatOptions chatOptions) {
|
||||
public Prompt(String contents, @Nullable ChatOptions chatOptions) {
|
||||
this(new UserMessage(contents), chatOptions);
|
||||
}
|
||||
|
||||
public Prompt(Message message, ChatOptions chatOptions) {
|
||||
public Prompt(Message message, @Nullable ChatOptions chatOptions) {
|
||||
this(Collections.singletonList(message), chatOptions);
|
||||
}
|
||||
|
||||
public Prompt(List<Message> messages, ChatOptions chatOptions) {
|
||||
public Prompt(List<Message> messages, @Nullable ChatOptions chatOptions) {
|
||||
Assert.notNull(messages, "messages cannot be null");
|
||||
Assert.noNullElements(messages, "messages cannot contain null elements");
|
||||
this.messages = messages;
|
||||
this.chatOptions = (chatOptions != null) ? chatOptions : ChatOptions.builder().build();
|
||||
this.chatOptions = chatOptions;
|
||||
}
|
||||
|
||||
public String getContents() {
|
||||
@@ -89,6 +90,7 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatOptions getOptions() {
|
||||
return this.chatOptions;
|
||||
}
|
||||
@@ -134,7 +136,7 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
}
|
||||
|
||||
public Prompt copy() {
|
||||
return new Prompt(instructionsCopy(), this.chatOptions.copy());
|
||||
return new Prompt(instructionsCopy(), null == this.chatOptions ? null : this.chatOptions.copy());
|
||||
}
|
||||
|
||||
private List<Message> instructionsCopy() {
|
||||
@@ -196,7 +198,9 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
|
||||
public Builder mutate() {
|
||||
Builder builder = new Builder().messages(instructionsCopy());
|
||||
builder.chatOptions(this.chatOptions.copy());
|
||||
if (this.chatOptions != null) {
|
||||
builder.chatOptions(this.chatOptions.copy());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -232,6 +236,7 @@ public class Prompt implements ModelRequest<List<Message>> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Builder addMessage(Message message) {
|
||||
if (this.messages == null) {
|
||||
this.messages = new ArrayList<>();
|
||||
|
||||
@@ -29,7 +29,12 @@ public class ImagePrompt implements ModelRequest<List<ImageMessage>> {
|
||||
private ImageOptions imageModelOptions;
|
||||
|
||||
public ImagePrompt(List<ImageMessage> messages) {
|
||||
this(messages, ImageOptionsBuilder.builder().build());
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public ImagePrompt(List<ImageMessage> messages, ImageOptions imageModelOptions) {
|
||||
this.messages = messages;
|
||||
this.imageModelOptions = imageModelOptions;
|
||||
}
|
||||
|
||||
public ImagePrompt(ImageMessage imageMessage, ImageOptions imageOptions) {
|
||||
@@ -44,11 +49,6 @@ public class ImagePrompt implements ModelRequest<List<ImageMessage>> {
|
||||
this(new ImageMessage(instructions), ImageOptionsBuilder.builder().build());
|
||||
}
|
||||
|
||||
public ImagePrompt(List<ImageMessage> messages, ImageOptions imageModelOptions) {
|
||||
this.messages = messages;
|
||||
this.imageModelOptions = imageModelOptions != null ? imageModelOptions : ImageOptionsBuilder.builder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImageMessage> getInstructions() {
|
||||
return this.messages;
|
||||
|
||||
Reference in New Issue
Block a user