Skip to contents

Generate text completions using OpenAI's API for Chat

Usage

openai_create_chat_completion(
  prompt = "<|endoftext|>",
  model = getOption("gptstudio.model"),
  openai_api_key = Sys.getenv("OPENAI_API_KEY"),
  task = "chat/completions"
)

Arguments

prompt

The prompt for generating completions

model

The model to use for generating text

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!"
)
}