Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* @author Josh Long
* @author Jemin Huh
* @author Grogdunn
* @author Hyunjoon Choi
* @see ChatModel
* @see StreamingChatModel
* @see OpenAiApi
Expand All @@ -86,7 +87,7 @@ public class OpenAiChatModel extends
/**
* The retry template used to retry the OpenAI API calls.
*/
public final RetryTemplate retryTemplate;
private final RetryTemplate retryTemplate;

/**
* Low-level access to the OpenAI API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,54 @@
*
* @author Mark Pollack
* @author Christian Tzolov
* @author Hyunjoon Choi
* @since 0.8.0
*/
public class OpenAiImageModel implements ImageModel {

private final static Logger logger = LoggerFactory.getLogger(OpenAiImageModel.class);

/**
* The default options used for the image completion requests.
*/
private OpenAiImageOptions defaultOptions;

private final OpenAiImageApi openAiImageApi;
/**
* The retry template used to retry the OpenAI Image API calls.
*/
private final RetryTemplate retryTemplate;

public final RetryTemplate retryTemplate;
/**
* Low-level access to the OpenAI Image API.
*/
private final OpenAiImageApi openAiImageApi;

/**
* Creates an instance of the OpenAiImageModel.
* @param openAiImageApi The OpenAiImageApi instance to be used for interacting with
* the OpenAI Image API.
* @throws IllegalArgumentException if openAiImageApi is null
*/
public OpenAiImageModel(OpenAiImageApi openAiImageApi) {
this(openAiImageApi, OpenAiImageOptions.builder().build(), RetryUtils.DEFAULT_RETRY_TEMPLATE);
}

public OpenAiImageModel(OpenAiImageApi openAiImageApi, OpenAiImageOptions defaultOptions,
RetryTemplate retryTemplate) {
/**
* Initializes a new instance of the OpenAiImageModel.
* @param openAiImageApi The OpenAiImageApi instance to be used for interacting with
* the OpenAI Image API.
* @param options The OpenAiImageOptions to configure the image model.
* @param retryTemplate The retry template.
*/
public OpenAiImageModel(OpenAiImageApi openAiImageApi, OpenAiImageOptions options, RetryTemplate retryTemplate) {
Assert.notNull(openAiImageApi, "OpenAiImageApi must not be null");
Assert.notNull(defaultOptions, "defaultOptions must not be null");
Assert.notNull(options, "options must not be null");
Assert.notNull(retryTemplate, "retryTemplate must not be null");
this.openAiImageApi = openAiImageApi;
this.defaultOptions = defaultOptions;
this.defaultOptions = options;
this.retryTemplate = retryTemplate;
}

public OpenAiImageOptions getDefaultOptions() {
return this.defaultOptions;
}

@Override
public ImageResponse call(ImagePrompt imagePrompt) {
return this.retryTemplate.execute(ctx -> {
Expand Down Expand Up @@ -158,4 +176,8 @@ private OpenAiImageOptions toOpenAiImageOptions(ImageOptions runtimeImageOptions
return openAiImageOptionsBuilder.build();
}

public OpenAiImageOptions getDefaultOptions() {
return this.defaultOptions;
}

}