completions4R {chatAI4R}R Documentation

completions4R: Generate text using OpenAI completions API (Legacy)

Description

This function sends a request to the OpenAI completions API (Legacy) to generate text based on the provided prompt and parameters.

Usage

completions4R(
  prompt,
  api_key = Sys.getenv("OPENAI_API_KEY"),
  Model = "text-davinci-003",
  max_tokens = 50,
  temperature = 1,
  simple = TRUE
)

Arguments

prompt

A string. The initial text that the model responds to.

api_key

A string. The API key for OpenAI. Defaults to the value of the environment variable "OPENAI_API_KEY".

Model

A string. The model ID to use, such as "text-davinci-003".

max_tokens

Integer. The maximum number of tokens to generate.

temperature

A numeric value to control the randomness of the generated text. A value close to 0 produces more deterministic output, while a higher value (up to 2) produces more random output.

simple

If TRUE, returns the generated text without newline characters. If FALSE, returns the full response from the API.

Value

The generated text or the full response from the API, depending on the value of 'simple'.

Author(s)

Satoshi Kume

Examples

## Not run: 
Sys.setenv(OPENAI_API_KEY = "Your API key")

prompt <- "Translate the following English text to French: 'Hello, world!'"

completions4R(prompt)

## End(Not run)

[Package chatAI4R version 0.2.10 Index]