Introduction
In this article, we’ll review a small netbeans plugin i’ve developed to integrate chatgpt with my favorite IDE.
TL;DR
You can find the source code covered in this blog at GitHub.
NetBeans ChatGPT Plugin
This plugin allows you to use OpenAI’s APIs to generate chat responses directly in NetBeans. I’ll probably add some editor context menu actions to speed up code suggestions, but for now its a simple UI for chat that lives in Netbeans.
Please click on any photo to view in a lightbox.
Installation
- Download the plugin file (.nbm file)
- In NetBeans, go to
Tools > Plugins
. - Click on the
Downloaded
tab. - Click on the
Add Plugins...
button and select the downloaded ZIP file. - Set the
OPENAI_TOKEN
environment variable with your OpenAI API key - Restart NetBeans
Usage
Before you can use this plugin, you need to set the OPENAI_TOKEN
environment variable with your OpenAI API key. Below are instructions for different operating systems:
Setting the OPENAI_TOKEN Environment Variable
Unix-like Systems (Linux, macOS)
Open a terminal and run the following command to set the environment variable. This will be temporary and limited to the current session:
export OPENAI_TOKEN=your_token_here
To make it permanent, add the line to your shell configuration file (~/.bashrc, ~/.zshrc, etc.):
echo 'export OPENAI_TOKEN=your_token_here' >> ~/.bashrc # For Bash
echo 'export OPENAI_TOKEN=your_token_here' >> ~/.zshrc # For Zsh
Windows
Windows Powershell
Open powershell Prompt and run:
[Environment]::SetEnvironmentVariable("OPENAI_TOKEN", "your_token_here", [System.EnvironmentVariableTarget]::User)
Windows Using System GUI
- Right-click on ‘This PC’ or ‘Computer’ on the desktop or in File Explorer.
- Choose ‘Properties’.
- Click on ‘Advanced system settings’.
- In the ‘System Properties’ window, click on the ‘Environment Variables…’ button.
- Under the ‘User variables’ section, click ‘New…’ to create a new environment variable.
- Enter
OPENAI_TOKEN
as the variable name and your OpenAI API key as the variable value. - Click ‘OK’ to save.
After setting the OPENAI_TOKEN
environment variable through the system properties, you’ll need to restart any Command Prompts or IDEs for the new setting to take effect.