Join the new Discord server and start contributing to this project!
A simple, lightweight shell script to use OpenAI's chatGPT and DALL-E from the terminal without installing python or node.js. The script uses the official ChatGPT model gpt-3.5-turbo
with the OpenAI API endpoint /chat/completions
. You can also use the new gpt-4
model, if you have access.
The script supports the use of all other OpenAI models with the completions
endpoint and the images/generations
endpoint for generating images.
Chat mode:
$ chatgpt
Welcome to chatgpt. You can quit with 'exit'.
Enter a prompt:
Chat mode with initial prompt:
$ chatgpt -i "You are Rick, from Rick and Morty. Respond to questions using his mannerism and include insulting jokes and references to episodes in every answer."
Welcome to chatgpt. You can quit with 'exit'.
Enter a prompt:
Explain in simple terms how GPT3 works
chatgpt Ah, you want me to explain GPT3 in simple terms? Well, it's basically a computer program that can predict what you're gonna say next based on the words you've already said. Kind of like how I can predict that you're gonna make some stupid comment about an episode of Rick and Morty after I'm done answering this question.
Enter a prompt:
Using pipe:
echo "How to view running processes on Ubuntu?" | chatgpt
Using script parameters:
chatgpt -p "What is the regex to match an email address?"
This script relies on curl for the requests to the api and jq to parse the json response.
curl
brew install curl
jq
brew install jq
An OpenAI API key. Create an account and get a free API Key at OpenAI
Optionally, you can install glow to render responses in markdown
To install, run this in your terminal and provide your OpenAI API key when asked.
curl -sS https://raw.githubusercontent.com/0xacx/chatGPT-shell-cli/main/install.sh | sudo -E bash
If you are using ArchLinux you can install the AUR package with:
paru -S chatgpt-shell-cli
If you want to install it manually, all you have to do is:
chatgpt.sh
file in a directory you wantchatgpt.sh
to your $PATH
. You do that by adding this line to your shell profile: export PATH=$PATH:/path/to/chatgpt.sh
export OPENAI_KEY=your_key_here
chatgpt
command anywhere. By default the script uses the gpt-3.5-turbo
model.echo "What is the command to get all pdf files created yesterday?" | chatgpt
chatgpt -p "What is the regex to match an email address?"
image:
To generate images, start a prompt with image:
If you are using iTerm, you can view the image directly in the terminal. Otherwise the script will ask to open the image in your browser.history
To view your chat history, type history
models
To get a list of the models available at OpenAI API, type models
model:
To view all the information on a specific model, start a prompt with model:
and the model id
as it appears in the list of models. For example: model:text-babbage:001
will get you all the fields for text-babbage:001
modelcommand:
To get a command with the specified functionality and run it, just type command:
and explain what you want to achieve. The script will always ask you if you want to execute the command. i.e. command: show me all files in this directory that have more than 150 lines of code
If a command modifies your file system or dowloads external files the script will show a warning before executing.gpt-3.5-turbo
and gpt-4
where the chat context is not supported by the OpenAI api, you can use the chat context build in this script. You can enable chat context mode for the model to remember your previous chat questions and answers. This way you can ask follow-up questions. In chat context the model gets a prompt to act as ChatGPT and is aware of today's date and that it's trained with data up until 2021. To enable this mode start the script with -c
or --chat-context
. i.e. chatgpt --chat-context
and start to chat.-i
or --init-prompt
followed by your initial prompt i.e. chatgpt -i "You are Rick from Rick and Morty, reply with references to episodes."
--init-prompt-from-file
i.e. chatgpt --init-prompt-from-file myprompt.txt
*When you set an initial prompt you don't need to enable the chat context.
gpt-3.5-turbo
.gpt-4
, i.e. chatgpt --model gpt-4
To set request parameters you can start the script like this: chatgpt --temperature 0.9 --model text-babbage:001 --max-tokens 100 --size 1024x1024
The available parameters are:
-t
or --temperature
-m
or --model
--max-tokens
-s
or --size
(The sizes that are accepted by the OpenAI API are 256x256, 512x512, 1024x1024)-p
or --prompt
--prompt-from-file
To learn more about these parameters you can view the API documentation
Thanks to all the people who used, tested, submitted issues, PRs and proposed changes:
pfr-dev, jordantrizz, se7en-x230, mountaineerbr, oligeo, biaocy, dmd, goosegit11, dilatedpupils, direster, rxaviers, Zeioth, edshamis, nre-ableton, TobiasLaving, RexAckermann, emirkmo, np, camAtGitHub, keyboardsage tomas223
Contributions are very welcome!
If you have ideas or need help to get started join the Discord server