Class OpenAiImageModel

java.lang.Object
dev.langchain4j.model.openai.OpenAiImageModel
All Implemented Interfaces:
ImageModel

public class OpenAiImageModel extends Object implements ImageModel
Represents an OpenAI DALL·E models to generate artistic images. Versions 2 and 3 (default) are supported.
  • Constructor Details

    • OpenAiImageModel

      public OpenAiImageModel(String baseUrl, String apiKey, String organizationId, String modelName, String size, String quality, String style, String user, String responseFormat, Duration timeout, Integer maxRetries, Proxy proxy, Boolean logRequests, Boolean logResponses, Boolean withPersisting, Path persistTo, Map<String,String> customHeaders)
      Instantiates OpenAI DALL·E image processing model. Find the parameters description here.
      Parameters:
      modelName - dall-e-3 is default one
      withPersisting - generated response will be persisted under java.io.tmpdir. The URL within dev.ai4j.openai4j.image.GenerateImagesResponse will contain the URL to local images then.
      persistTo - specifies the local path where the generated image will be downloaded to (in case provided). The URL within dev.ai4j.openai4j.image.GenerateImagesResponse will contain the URL to local images then.
  • Method Details

    • modelName

      public String modelName()
    • generate

      public Response<Image> generate(String prompt)
      Description copied from interface: ImageModel
      Given a prompt, generate an image.
      Specified by:
      generate in interface ImageModel
      Parameters:
      prompt - The prompt to generate an image from.
      Returns:
      The generated image Response.
    • generate

      public Response<List<Image>> generate(String prompt, int n)
      Description copied from interface: ImageModel
      Given a prompt, generate n images.

      Not supported by all models; as explicit support is needed to generate different images from the same prompt.

      Specified by:
      generate in interface ImageModel
      Parameters:
      prompt - The prompt to generate images from.
      n - The number of images to generate.
      Returns:
      The generated images Response.
    • builder

    • withApiKey

      public static OpenAiImageModel withApiKey(String apiKey)