View source: R/completions4R.R
| completions4R | R Documentation |
**[WARNING] DEPRECATED AND SCHEDULED FOR REMOVAL**: This function uses the legacy OpenAI completions API which is being phased out by OpenAI. **This function will be removed in a future version.**
**MIGRATION REQUIRED**: Please migrate to chat4R() for all new implementations. The chat4R() function uses the modern OpenAI Chat Completions API and provides better performance, more features, and continued support.
**Migration Example**: “'r # Old (deprecated): result <- completions4R("Your prompt here")
# New (recommended): result <- chat4R("Your prompt here") text_content <- result$content “'
This function sends a request to the OpenAI completions API to generate text based on the provided prompt and parameters.
completions4R(
prompt,
api_key = Sys.getenv("OPENAI_API_KEY"),
Model = "gpt-3.5-turbo-instruct",
max_tokens = 50,
temperature = 1,
simple = TRUE
)
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 "davinci-002" or "gpt-3.5-turbo-instruct". |
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. |
The generated text or the full response from the API, depending on the value of 'simple'.
Satoshi Kume
## Not run:
# DEPRECATED: Use chat4R() instead for new code
Sys.setenv(OPENAI_API_KEY = "Your API key")
prompt <- "Translate the following English text to French: 'Hello, world!'"
completions4R(prompt)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.