Learn R Programming

openaiRtools (version 0.2.2)

create_image: Generate an Image from Text (Convenience Function)

Description

Shortcut that creates an OpenAI client from the OPENAI_API_KEY environment variable and calls client$images$create().

Usage

create_image(prompt, model = "dall-e-3", ...)

Value

A list with $data[[1]]$url containing the image URL, and $data[[1]]$revised_prompt with the prompt used by DALL-E 3.

Arguments

prompt

Character. Required. Text description of the desired image. For DALL-E 3, up to 4000 characters.

model

Character. Image model: "dall-e-3" (default) or "dall-e-2".

...

Additional parameters passed to ImagesClient$create(), such as n, size ("1024x1024", "1792x1024", "1024x1792"), quality ("standard" or "hd"), style ("vivid" or "natural"), response_format ("url" or "b64_json").

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "sk-xxxxxx")

# Generate a standard image
resp <- create_image("A futuristic chart showing economic data, neon style")
cat(resp$data[[1]]$url)

# HD landscape
resp <- create_image(
  prompt  = "A detailed map of global trade routes",
  model   = "dall-e-3",
  size    = "1792x1024",
  quality = "hd",
  style   = "natural"
)
cat(resp$data[[1]]$url)
}

Run the code above in your browser using DataLab