The goal of gptstudio is for R programmers to 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.
For further addins, tailored for R developers, also see the sister package: gpttools
To get a bug fix or to use a feature from the development version, you can install the development version of this package from GitHub.
# install.packages("pak") pak::pak("MichelNivard/gptstudio")
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
To interact with the OpenAI API, it’s required to have a valid
OPENAI_API_KEY environment variable. Here are the steps to configure it.
You can establish this environment variable globally by including it in your project’s .Renviron file. This approach ensures that the environment variable persists across all sessions as the Shiny app runs in the background.
Here is a set of commands to open the .Renviron file for modification:
If you wish to set the variable temporarily for a single session, use this command, substituting
"<APIKEY>" with your actual OpenAI API key:
Sys.setenv(OPENAI_API_KEY = "<APIKEY>")
For a persistent setting that loads every time you launch this project, add the following line to .Renviron, replacing
"<APIKEY>" with your actual API key:
Caution: If you’re using version control systems like GitHub or GitLab, remember to include .Renviron in your .gitignore file to prevent exposing your API key!
Important Note: OpenAI API will not function without valid payment details entered into your OpenAI account. This is a restriction imposed by OpenAI and is unrelated to this package.
Some examples of use.
- Addins > gptstudio > ChatGPT
- Type your question.
- Click “Send” button or press “Enter”
- Ask more questions
- Copy and try code
The ChatGPT addin supports internationalization. You can set the “GPTSTUDIO_LANGUAGE” environmental variable to the language of your preference (i.e.
GPTSTUDIO_LANGUAGE="es" for spanish). See the full list of supported languages in the translation file (
We’re excited to announce that our service now includes models from HuggingFace’s inference API, Anthropic’s claude models, and Google’s MakerSuite, and Azure OpenAI service broadening the range of AI solutions you can use. You can set the model using the setting (gear) button in the ChatGPT addin app.
You can now save your app settings across sessions. These are saved in a user config file. The easiest way to change these settings is the “Save as Default” button in the add-in app. This also allows you to specify your own custom prompt to pass to the model as instructions.
Addins > GPTSTUDIO > ChatGPT in Source: Apply any edit what YOU desire or can dream up to a selection of code or text.
Addins > GPTSTUDIO > Spelling and Grammar: Takes the selected text sends it to OpenAI’s best model and instructs it to return a spelling and grammar checked version.
To configure gptstudio to work using Azure OpenAI service, you need to provide some configuration details in your .Renviron file. Specifically, gptstudio looks for five environment variables:
Here’s how you can add these details to your .Renviron file:
- Locate your .Renviron file with
- Add environment variable details: Add a new line for each variable you need to set in the following format: VARIABLE_NAME=“YOUR_VALUE”. Replace VARIABLE_NAME with the name of the environment variable and YOUR_VALUE with the actual value that you want to set. For example, to set the API key you would have a line like this:
You need to do this for each of the environment variables expected by the function. Your .Renviron file should look something like this:
AZURE_OPENAI_TASK="your_task_code" AZURE_OPENAI_ENDPOINT="your_endpoint_url" AZURE_OPENAI_DEPLOYMENT_NAME="your_deployment_name" AZURE_OPENAI_KEY="your_api_key" AZURE_OPENAI_API_VERSION="your_api_version"
- Save and Close .Renviron: After adding your environment variables, save your .Renviron file and close it. You will need to restart your R session to make sure the new environment variables are loaded properly.
Remember to replace your_task_code, your_endpoint_url, your_deployment_name, your_api_key, and your_api_version with your actual Azure OpenAI details. You can retrieve these details from your Azure OpenAI service account. For more information about Azure OpenAI configuration, refer to the Microsoft quickstart guide.
Please note that the gptstudio project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.