Skip to contents

Generate text completions using OpenAI's API

Usage

openai_create_completion(
  model = "text_davinci-003",
  prompt = "<|endoftext|>",
  suffix = NULL,
  max_tokens = 16,
  temperature = NULL,
  top_p = NULL,
  openai_api_key = Sys.getenv("OPENAI_API_KEY"),
  task = "completions"
)

Arguments

model

The model to use for generating text

prompt

The prompt for generating completions

suffix

The suffix for generating completions. If NULL, no suffix will be used.

max_tokens

The maximum number of tokens to generate.

temperature

The temperature to use for generating text (between 0 and 1). If NULL, the default temperature will be used. It is recommended NOT to specify temperature and top_p at a time.

top_p

The top-p value to use for generating text (between 0 and 1). If NULL, the default top-p value will be used. It is recommended NOT to specify temperature and top_p at a time.

openai_api_key

The API key for accessing OpenAI's API. By default, the function will try to use the OPENAI_API_KEY environment variable.

task

The task that specifies the API url to use, defaults to "completions" and "chat/completions" is required for ChatGPT model.

Value

A list with the generated completions and other information returned by the API.

Examples

if (FALSE) {
openai_create_completion(
  model = "text-davinci-002",
  prompt = "Hello world!"
)
}