This is a very simple commandline interface for the OpenAI ChatGPT API built using node
- Node (version 16 or newer)
- npm
- Clone this repository on your computer
- Navigate to the project root on your terminal
- Rename the
.env.example
file to.env
, and add your OpenAI API key to theOPENAI_API_KEY
- variable. You can also adjust the configuration to your liking. Get your API key here: https://platform.openai.com/docs/quickstart/add-your-api-key - Run
npm run build
- Make the script executable by running
sudo chmod +x ./dist/chatgpt-cli.js
- You can now run the script:
./dist/chatgpt-cli.js
- You may want to alias the path to the script in your shell. Here's how you can do it if you're using bash:
- Get the absolute path to the script. You can do this by running
pwd
inside the dist -folder, and appending the name of the script to the path. - Open your
.bashrc
-file in your editor of choice. The file should be located in your home directory. - To the bottom of the file, add the following line:
alias chatgpt="/absolute/path/to/script/here"
, and replace the part in quotes with the absolute path to the script. - Either reboot your computer, or run the following command in your terminal:
source ~/.bashrc
(assuming your .bashrc -file is inside your home directory) - You can now run
chatgpt
on your terminal, and the script should start.
- Get the absolute path to the script. You can do this by running
Simply write your question when prompted, and press enter twice to submit. To cancel your prompt and exit the program, press ctrl+c
.
If you'd like ChatGPT to remember your previous questions in the current session, you can set the INCLUDE_HISTORY
environment variable to "true"
. This will include your previous questions and responses in every subsequent request, which will inevitably use more tokens. To clear your history, simply exit the current session with ctrl+c
and start a new one.