Learn R Programming

GenAI (version 0.2.0)

img: Image Generation with Text as the Input

Description

This function establishes a connection to a generative AI model through a generative AI object. It generates an image response based on the provided prompt.

Usage

img(genai.object, prompt, verbose = FALSE, config = list())

Value

If successful, a image in ggplot format will be returned. If the API response indicates an error, the function halts execution and provides an error message.

Arguments

genai.object

A generative AI object containing necessary and correct information.

prompt

A character string representing the query for image generation.

verbose

Optional. Default to FALSE. A boolean value determining whether or not to print out the details of the image request.

config

Optional. Default to list(). A list of configuration parameters for image generation.

Details

Providing accurate and valid information for each argument is crucial for successful image generation by the generative AI model. If any parameter is incorrect, the function responds with an error message based on the API feedback. To view all supported generative AI models, use the function available.models.

This function is only available when using OpenAI's models.

For OpenAI models, available configurations are as follows. For more detail, please refer to https://platform.openai.com/docs/api-reference/images/create.

  • quality

    Optional. A character string. The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image.

  • size

    Optional. A character string. The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2. Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models.

  • style

    Optional. The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images.

  • user

    Optional. A character string. A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

See Also

Examples

Run this code
if (FALSE) {
# Assuming there is a GenAI object named 'genai.model' supporting this
# function, please refer to the "Live Demo in Colab" above for real
# examples. The following examples are just some basic guidelines.

# Method 1 (recommended): use the pipe operator "%>%"
generated.image = genai.model %>%
  img(prompt = "A very cute panda eating banboo.")
generated.image

# Method 2: use the reference operator "$"
generated.image = genai.model$img(prompt = "A very cute sea otter on a rock.")
generated.image

# Method 3: use the function img() directly
generated.image = img(genai.object = genai.model,
                      prompt = "A very cute bear.")
generated.image
}

Run the code above in your browser using DataLab