Skip to contents

Creates a completion based on the provided prompt and parameters. See this page for details.

Usage

create_completion(
  engine_id,
  prompt = "<|endoftext|>",
  suffix = NULL,
  max_tokens = 16,
  temperature = 1,
  top_p = 1,
  n = 1,
  stream = FALSE,
  logprobs = NULL,
  echo = FALSE,
  stop = NULL,
  presence_penalty = 0,
  frequency_penalty = 0,
  best_of = 1,
  logit_bias = NULL,
  user = NULL,
  openai_api_key = Sys.getenv("OPENAI_API_KEY"),
  openai_organization = NULL
)

Arguments

engine_id

required; a length one character vector.

prompt

required; defaults to "<|endoftext|>"; an arbitrary length character vector.

suffix

optional; defaults to NULL; a length one character vector.

max_tokens

required; defaults to 16; a length one numeric vector with the integer value greater than 0.

temperature

required; defaults to 1; a length one numeric vector with the value between 0 and 2.

top_p

required; defaults to 1; a length one numeric vector with the value between 0 and 1.

n

required; defaults to 1; a length one numeric vector with the integer value greater than 0.

stream

required; defaults to FALSE; a length one logical vector. Currently is not implemented.

logprobs

optional; defaults to NULL; a length one numeric vector with the integer value between 0 and 5.

echo

required; defaults to FALSE; a length one logical vector.

stop

optional; defaults to NULL; a character vector of length between one and four.

presence_penalty

required; defaults to 0; a length one numeric vector with a value between -2 and 2.

frequency_penalty

required; defaults to 0; a length one numeric vector with a value between -2 and 2.

best_of

required; defaults to 1; a length one numeric vector with the integer value greater than 0.

logit_bias

optional; defaults to NULL; a named list.

user

optional; defaults to NULL; a length one character vector.

openai_api_key

required; defaults to Sys.getenv("OPENAI_API_KEY") (i.e., the value is retrieved from the .Renviron file); a length one character vector. Specifies OpenAI API key.

openai_organization

optional; defaults to NULL; a length one character vector. Specifies OpenAI organization.

Value

Returns a list, elements of which contain completion(s) and supplementary information.

Details

For arguments description please refer to the official documentation.

Examples

if (FALSE) {
create_completion(
    engine = "text-davinci-002",
    prompt = "Say this is a test",
    max_tokens = 5
)

logit_bias <- list(
    "11" = -100,
    "13" = -100
)
create_completion(
    engine_id = "ada",
    prompt = "Generate a question and an answer",
    n = 4,
    best_of = 4,
    logit_bias = logit_bias
)
}