Skip to content

horga83/shellChatGPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

281 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

shellChatGPT

Shell wrapper for OpenAI API for ChatGPT, DALL-E and Whisper.

Showing off Chat Completions

๐Ÿš€ Features

  • 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.

โœจ Getting Started

๐Ÿ’พ Installation

Just download the stand-alone chatgpt.sh and make it executable or clone this repo.

โœ”๏ธ Required packages

  • Free OpenAI GPTChat key
  • Bash or Zsh
  • cURL, and JQ
  • Imagemagick (optional)
  • Base64 (optional)
  • Sox/Arecord/FFmpeg (optional)

๐Ÿ”ฅ Usage

  • 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 -l and then set option -m [MODEL_NAME]
  • Some models require a single prompt while others instruction and input prompts
  • To generate images, set option -i and write your prompt
  • Make a variation of an image, set -i and an image path for upload

๐ŸŒŽ Environment

  • Set $OPENAI_API_KEY with your OpenAI API key.
  • Optionally, set $CHATGPTRC with path to the configuration file. Defaults = ~/.chatgpt.conf.

Examples

Chat cmpls with prompt confirmation

๐Ÿ“œ Text Completions

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."

Insert Mode of Text Completions

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.

Chat Mode of Text Completions

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  "

๐Ÿ’ฌ Native Chat Completions

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 .."

๐Ÿ”Œ Awesome Prompts

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!

Text Edits

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).

๐Ÿ–ผ๏ธ Image Generations

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."

Image Variations

Generate image variation:

chatgpt.sh -i path/to/image.png

Image Edits

chatgpt.sh -i path/to/image.png path/to/mask.png "A pink flamingo."

Outpaint - make a mask from the black colour:

Showing off Image Edits - Outpaint

Inpaint - add a bat in the night sky:

Showing off Image Edits - Inpaint

Inpaint, steps

๐Ÿ”Š Audio Transcriptions / Translations

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

Transcribe audio with timestamps

๐Ÿ—ฃ๏ธ Voice + Chat Completions

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

Code Completions (Codex)

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.

โš™๏ธ Prompts

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.

๐Ÿš Shell Interpreters

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.

Arch Linux Users

There is a PKGBUILD entry available to install the package in Arch Linux and derivative distros.

Termux Users

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

๐ŸŽฏ Project Objectives

  • Implement most features available from OpenAI API
  • Provide the closest API defaults
  • Let the user customise defaults (homework)

Distinct Features

  • 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.

โš ๏ธ Limitations

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.

๐Ÿ“– Help Pages

Read the markdown man page here.

Alternatively, a help page snippet can be printed with chatgpt.sh -h.

๐Ÿ’ช Contributors

Many Thanks to all that contributed to this project.

edshamis


Everyone is welcome to submit issues, PRs, and new ideas!

About

Shell wrapper for ChatGPT, DALL-E, Whisper, and awesome-chatgpt-prompts(-zh).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages