Class WatsonxGatewayImageModel

java.lang.Object
dev.langchain4j.model.watsonx.WatsonxGatewayImageModel
All Implemented Interfaces:
ImageModel

public class WatsonxGatewayImageModel extends Object implements ImageModel
An ImageModel implementation that integrates the IBM watsonx.ai Model Gateway with LangChain4j.

Example usage:

ImageModel imageModel = WatsonxGatewayImageModel.builder()
    .baseUrl("https://...") // or use CloudRegion
    .apiKey("...")
    .modelName("gpt-image-1")
    .build();

Image image = imageModel.generate("A futuristic city at sunset").content();
  • Method Details

    • modelName

      public String modelName()
      Returns the id of the gateway model used to generate the images.
      Returns:
      the model id
    • generate

      public Response<Image> generate(String prompt)
      Generates a single image from the given prompt, using the parameters set on the builder.
      Specified by:
      generate in interface ImageModel
      Parameters:
      prompt - the description of the image to generate
      Returns:
      the generated image
    • generate

      public Response<List<Image>> generate(String prompt, int n)
      Generates n images from the given prompt, using the parameters set on the builder.
      Specified by:
      generate in interface ImageModel
      Parameters:
      prompt - the description of the images to generate
      n - the number of images to generate, from 1 to 10
      Returns:
      the generated images
    • generate

      public Response<List<Image>> generate(String prompt, com.ibm.watsonx.ai.gateway.image.ModelGatewayImageParameters parameters)
      Generates images from the given prompt, using the specified ModelGatewayImageParameters.

      The given parameters replace the ones set on the builder, they are not merged with them.

      Parameters:
      prompt - the description of the images to generate
      parameters - the image parameters to use, or null to use the ones set on the builder
      Returns:
      the generated images
    • builder

      public static WatsonxGatewayImageModel.Builder builder()
      Returns a new WatsonxGatewayImageModel.Builder instance.

      Example usage:

      ImageModel imageModel = WatsonxGatewayImageModel.builder()
          .baseUrl("https://...") // or use CloudRegion
          .apiKey("...")
          .modelName("gpt-image-1")
          .build();
      
      Returns:
      WatsonxGatewayImageModel.Builder instance.