Learn R Programming

openaiRtools (version 0.2.2)

create_completion: Create a Legacy Text Completion (Convenience Function)

Description

Note: This is the legacy Completions API. For most tasks, use create_chat_completion() instead, which supports system prompts, conversation history, and more capable models.

Usage

create_completion(prompt, model = "gpt-3.5-turbo-instruct", ...)

Value

A named list. Access the generated text via $choices[[1]]$text.

Arguments

prompt

Character. Required. The text prompt to complete.

model

Character. Model ID. Only "gpt-3.5-turbo-instruct", "davinci-002", and "babbage-002" support this endpoint. Default: "gpt-3.5-turbo-instruct".

...

Additional parameters passed to CompletionsClient$create(), such as max_tokens, temperature, n, stop, stream, etc.

Details

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

Examples

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

# Complete a sentence
resp <- create_completion(
  prompt     = "The most important assumption of OLS regression is",
  model      = "gpt-3.5-turbo-instruct",
  max_tokens = 100
)
cat(resp$choices[[1]]$text)
}

Run the code above in your browser using DataLab