• Stars
    star
    291
  • Rank 142,563 (Top 3 %)
  • Language
    R
  • License
    Other
  • Created almost 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

gpttools extends gptstudio for package development to help you document code, write tests, or even explain code

gpttools

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. CRAN status gpttools status badge Codecov test coverage Lifecycle: experimental R-CMD-check Last Commit pre-commit

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.

Installation

Install from GitHub with {pak}

# install.packages("pak")
pak::pak("JamesHWade/gpttools")

Install from R-Universe

# Enable repository from jameshwade
options(repos = c(
  jameshwade = "https://jameshwade.r-universe.dev",
  CRAN = "https://cloud.r-project.org"
))
# Download and install gpttools in R
install.packages("gpttools")
# Browse the gpttools manual pages
help(package = "gpttools")

Privacy Notice for 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.

Data Sharing with 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.

Security and Data Usage by OpenAI

We cannot guarantee the security of the data you send to OpenAI via the API, nor can we provide details on how OpenAI processes or uses your data. However, OpenAI has stated that they utilize prompts and results to enhance their AI models, as outlined in their terms of use. You can opt-out of this data usage by contacting OpenAI directly and making an explicit request.

Limiting Data Sharing

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.

Prerequisites

  1. Make an OpenAI account.

  2. Create an OpenAI API key to use with the package.

  3. Set the API key up in Rstudio

Setting OpenAI API Key

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:

require(usethis)
edit_r_environ(scope = "project")

You can add the following line to .Renviron (again, replace "<APIKEY>" with your actual key):

OPENAI_API_KEY= "<APIKEY>")

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!

Usage

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 text 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.

Comment Code

comment_code.mov

Add Roxygen

add_roxygen.mov

Convert a Script into Functions

from_script_to_functions.mov

Suggest a Unit Test for a Function

suggest_unit_test.mov

Code of Conduct

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.