Shell wrapper for OpenAI API for ChatGPT, DALL-E and Whisper.
- Text and chat completions.
- Insert mode of text completions.
- Follow up conversations, preview/regenerate responses
- Manage sessions, continue from last session, print last session.
- Integration with awesome-chatgpt-prompts and awesome-chatgpt-prompts-zh
- Generate images from text input
- Generate variations of images
- Edit images, easily generate an alpha mask
- Transcribe audio from various languages
- Translate audio into English text
- Record prompt voice, hear the answer back from the AI (pipe to voice synthesiser)
- Choose amongst available models
- Lots of command line options
- Converts base64 JSON data to PNG image
- Shouldโข work on Linux, FreeBSD, MacOS, and Termux.
Just download the stand-alone chatgpt.sh and make it executable or clone this repo.
- Free OpenAI GPTChat key
- Bash or Zsh
- cURL, and JQ
- Imagemagick (optional)
- Base64 (optional)
- Sox/Arecord/FFmpeg (optional)
- Set your OpenAI API key with option
-K [KEY]or environment variable$OPENAI_API_KEY - Just write your prompt after the script name
chatgpt.sh - Chat mode may be configured with Instruction or not.
- Set temperature value with
-t [VAL](0.0 to 2.0), defaults=0. - To set your model, run
chatgpt.sh -land then set option-m [MODEL_NAME] - Some models require a single
promptwhile othersinstructionandinputprompts - To generate images, set
option -iand write your prompt - Make a variation of an image, set -i and an image path for upload
- Set
$OPENAI_API_KEYwith your OpenAI API key. - Optionally, set
$CHATGPTRCwith path to the configuration file. Defaults =~/.chatgpt.conf.
One-shot text completion:
chatgpt.sh "Hello there! What is your name?"
Text completion with Curie model:
chatgpt.sh -m'text-curie-001' "Hello there! What is your name?"
chatgpt.sh -m1 "List biggest cities in the world."
For better results, set an instruction/system prompt:
chatgpt.sh -S'You are an AI assistant.' "List biggest cities in the world."
Set option -q to enable insert mode and add the
string [insert] where the model should insert text:
chatgpt.sh -q 'It was raining when [insert] tomorrow.'
Insert mode
works with davinci, text-davinci-002, and text-davinci-003.
With option -c, some options are set automatically to create a chat bot with text completions.
chatgpt.sh -c "Hello there! What is your name?"
Create Marv, the sarcastic bot manually:
chatgpt.sh -du -60 --frequency-penalty=0.5 --temp=0.5 --top_p=0.3 --restart-seq='\nYou: ' --start-seq='\nMarv:' --stop='You:' --stop='Marv:' -S'Marv is a chatbot that reluctantly answers questions with sarcastic responses:'
Tip: set -VV to see the actual request body and how options are set!
Complete text in multi-turn:
chatgpt.sh -d -S'The following is a newspaper article.' "It all starts when FBI agents arrived at the governor house and "
Start a new session in chat mode, and set a different temperature:
chatgpt.sh -cc -t0.7
Chat mode in text editor (visual) mode. Edit initial input:
chatgpt.sh -ccx "Complete the story: Alice visits Bob. John arrives .."
Set a prompt from awesome-chatgpt-prompts or awesome-chatgpt-prompts-zh, (use with Davinci or gpt-3.5+ models):
chatgpt.sh -cc -S /linux_terminal
chatgpt.sh -cc -S /Relationship_Coach
chatgpt.sh -cc -S %ๆ
ไปป้
ๆๅไฝ่ๅฎ
Alternatively, some simple prompts to get one started include:
chatgpt.sh -cc -S'You are a professional psicologist.'
chatgpt.sh -cc -S'You are a professional software programmer.'
chatgpt.sh -cc -S'You are a post-graduation teacher and will do various activities related to preparing and elaborating a Philosophy course.'
*Obs: in this case, the instruction (or system prompt) may refer to both user and assistant roles, so heed your own instruction!
Choose an edit model or set option -e to use this endpoint.
Two prompts are accepted, an instruction prompt and
an input prompt (optional):
chatgpt.sh -e "Fix spelling mistakes" "This promptr has spilling mistakes."
chatgpt.sh -e "Shell code to move files to trash bin." ""
Edits works great with INSTRUCTION and an empty prompt (e.g. to create some code based on instruction only).
Generate image according to prompt:
chatgpt.sh -i "Dark tower in the middle of a field of red roses."
chatgpt.sh -i "512x512" "A tower."
Generate image variation:
chatgpt.sh -i path/to/image.png
chatgpt.sh -i path/to/image.png path/to/mask.png "A pink flamingo."
Generate transcription from audio file. A prompt to guide the model's style is optional. The prompt should match the audio language:
chatgpt.sh -w path/to/audio.mp3
chatgpt.sh -w path/to/audio.mp3 "en" "This is a poem about X."
Generate transcription from voice recording, set Portuguese as the language to transcribe to:
chatgpt.sh -w pt
Also works to transcribe from one language to another.
Transcribe any language audio to japanese (prompt must be in the same language as the input audio language):
chatgpt.sh -w ja "An interview."
Translate audio file or voice recording in any language to English:
chatgpt.sh -W [audio_file]
chatgpt.sh -W
Transcribe audio and print timestamps option -ww:
chatgpt.sh -ww pt audio_in.mp3
Chat completion with voice as input:
chatgpt.sh -ccw
Chat in Portuguese with voice in and voice out (pipe output to voice synthesiser):
chatgpt.sh -ccw pt | espeakng -v pt-br
chatgpt.sh -ccw pt | termux-tts-speak -l pt -n br
Codex models are discontinued. Use davinci models or gpt-3.5+.
Start with a commented out code or instruction for the model, or ask it in comments to optimise the following code, for example.
Unless the chat option -c or -cc are set, no instruction is
given to the language model. On chat mode, if no instruction is set,
minimal instruction is given, and some options set, such as increasing
temp and presence penalty, in order to un-lobotomise the bot.
Prompt engineering is an art on itself. Study carefully how to craft the best prompts to get the most out of text, code and chat completions models.
Note that the model's steering and capabilities require prompt engineering to even know that it should answer the questions.
The script can be run with either Bash, or Zsh.
There should be equivalency of features under Bash, and Zsh.
Zsh is faster than Bash in respect to some features.
There is a PKGBUILD entry available to install the package in Arch Linux and derivative distros.
To run tiktoken with option -T, be sure to have your system
updated and installed with python, rust, and rustc-dev packages
for building python tiktoken.
$ pkg update
$ pkg upgrade
$ pkg install python rust rustc-dev
$ pip install tiktoken
- Implement most features available from OpenAI API
- Provide the closest API defaults
- Let the user customise defaults (homework)
- Run as single or multi-turn.
- Text editor interface, and single and multiline prompters.
- Manage sessions and history files.
- Run chat commands with operator
!or/. - In chat mode, edit live history entries with command
!hist. - Add operator forward slash
/to the end of prompt to trigger preview mode. - One can regenerate a response typing in a new prompt a single slash
/. - Set clipboard with the latest response with
option -o. - Hopefully, default colours are colour-blind friendly.
For a simple python wrapper for tiktoken, see tkn-cnt.py.
OpenAI API v1 is the focus of the present project implementation. New versions of the API may not be implemented. I would rather fix bugs of existing features than incorporate new ones.
See also BUGS section in the man page.
Read the markdown man page here.
Alternatively, a help page snippet can be printed with chatgpt.sh -h.
Many Thanks to all that contributed to this project.
Everyone is welcome to submit issues, PRs, and new ideas!





