Class WorkersAiImageModel

java.lang.Object
dev.langchain4j.model.workersai.client.AbstractWorkersAIModel
dev.langchain4j.model.workersai.WorkersAiImageModel
All Implemented Interfaces:
ImageModel

public class WorkersAiImageModel extends AbstractWorkersAIModel implements ImageModel
WorkerAI Image model.
  • Constructor Details

    • WorkersAiImageModel

      public WorkersAiImageModel(WorkersAiImageModel.Builder builder)
      Constructor with Builder.
      Parameters:
      builder - builder.
    • WorkersAiImageModel

      public WorkersAiImageModel(String accountId, String modelName, String apiToken)
      Constructor with Builder.
      Parameters:
      accountId - account identifier
      modelName - model name
      apiToken - api token
  • Method Details

    • builder

      public static WorkersAiImageModel.Builder builder()
      Builder access.
      Returns:
      builder instance
    • generate

      public Response<Image> generate(String prompt)
      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.
    • edit

      public Response<Image> edit(Image image, String prompt)
      Given an existing image, edit this image following the given prompt.
      Specified by:
      edit in interface ImageModel
      Parameters:
      image - The image to be edited.
      prompt - The prompt to edit the image.
      Returns:
      The generated image Response.
    • edit

      public Response<Image> edit(Image image, Image mask, String prompt)
      Given an existing image, edit this image following the given prompt and apply the changes only to the part of the image specified by the given mask.
      Specified by:
      edit in interface ImageModel
      Parameters:
      image - The image to be edited.
      mask - The image mask to apply to delimit the area to edit.
      prompt - The prompt to edit the image.
      Returns:
      The generated image Response.
    • generate

      public Response<File> generate(String prompt, String destinationFile)
      Generate image and save to file.
      Parameters:
      prompt - current prompt
      destinationFile - local file
      Returns:
      response with the destination file
    • getPixels

      public int[] getPixels(URL imageUrl) throws Exception
      Convert an image into a array of number, supposedly the Pixels.
      Parameters:
      imageUrl - current image URL
      Returns:
      pixels of the image
      Throws:
      Exception - return an exception if pixel not returned
    • convertAsImage

      public Image convertAsImage(byte[] data)
      Convert Workers AI Image Generation output to Langchain4j model.
      Parameters:
      data - output image
      Returns:
      output image converted