The goal of gpttools is to extend gptstudio for R package developers to more easily incorporate use of large language models (LLMs) into their project workflows. These models appear to be a step change in our use of text for knowledge work, but you should carefully consider ethical implications of using these models. Ethics of LLMs (also called Foundation Models) is an area of very active discussion.
# install.packages("pak") pak::pak("JamesHWade/gpttools")
This privacy notice is applicable to the R package that utilizes the GPT-3 and GPT-3.5 API provided by OpenAI. By using this package, you agree to adhere to the privacy terms and conditions set by OpenAI.
When using this R package, the text or code that you highlight/select with your cursor, or the prompt you enter within the built-in applications, will be sent to OpenAI as part of an API request. This data sharing is governed by the privacy notice, rules, and exceptions that you agreed to with OpenAI when creating an account.
The R package is designed to share only the text or code that you specifically highlight/select or include in a prompt through our built-in applications. No other elements of your R environment will be shared. It is your responsibility to ensure that you do not accidentally share sensitive data with OpenAI.
IMPORTANT: To maintain the privacy of your data, do not highlight, include in a prompt, or otherwise upload any sensitive data, code, or text that should remain confidential.
Make an OpenAI account.
Create an OpenAI API key to use with the package.
Set the API key up in Rstudio
By default, API calls will look for
OPENAI_API_KEY environment variable. If you want to set a global environment variable, you can use the following command, where
"<APIKEY>" should be replaced with your actual key:
Sys.setenv(OPENAI_API_KEY = "<APIKEY>")
Otherwise, you can add the key to the .Renviron file of the project. The following commands will open .Renviron for editing:
You can add the following line to .Renviron (again, replace
"<APIKEY>" with your actual key):
This now set the API key every time you start up this particular project. Note: If you are using GitHub/Gitlab, do not forget to add .Renviron to .gitignore!
The package has four addins:
Comment code: uses code-davinci-edit-001 model from OpenAI to add comments to your code with the prompt: “add comments to each line of code, explaining what the code does”
Add roxygen: uses text-davinci-003 model from OpenAI to add and fill out a roxygen skeleton to your highlight code (should be a function) with the prompt: “insert roxygen skeleton to document this function”
Convert script to function: uses code-davinci-edit-001 model from OpenAI to convert a highlighted script into a function with the prompt: “convert this R code into an R function”
Write a unit test for a function with testthat: uses text-davinci-003 model from OpenAI to suggest a unit test for a selected function with the prompt: “Suggest a unit test for this function using the testthat package”
A freeform addins that let’s you specify the prompt using the “edit” functionality of ChatGPT
You can access these addins through the addin toolbar or use the command pallet:
CMD/CTRL+SHIFT+P. Examples of each of the addins in action is below.
Please note that the gpttools project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.