Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/mountaineerbr/shellChatGPT

Shell wrapper for OpenAI's ChatGPT, DALL-E, Whisper, and TTS. Features LocalAI, Ollama, Gemini, and Mistral integration.
https://github.com/mountaineerbr/shellChatGPT

awesome-chatgpt-prompts awesome-chatgpt-prompts-zh bash chat-completions chatbot davinci gemini-api gemini-pro gpt-3-5-turbo-instruct gpt-4-vision localai mistral-api ollama terminal text-completions tts

Last synced: 2 months ago
JSON representation

Shell wrapper for OpenAI's ChatGPT, DALL-E, Whisper, and TTS. Features LocalAI, Ollama, Gemini, and Mistral integration.

Lists

README

        

# shellChatGPT
Shell wrapper for OpenAI's ChatGPT, DALL-E, Whisper, and TTS. Features LocalAI, Ollama, Gemini and Mistral integration.

![Showing off Chat Completions](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/chat_cpls.gif)

Chat completions with streaming by defaults.

![Chat with Markdown rendering](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/chat_cpls_md.gif)

Markdown rendering of chat response (_optional_).

## ๐Ÿš€ Features

- Text and chat completions with [**gtp-4-vision** support](#vision-models-gpt-4-vision)
- **Text editor interface**, _Bash readline_, and _cat_ input modes
- [**Markdown rendering**](#markdown) support in response
- **Preview**, and [**regenerate responses**](#--notes-and-tips)
- **Manage sessions**, _print out_ previous sessions
- [Instruction prompt manager](#%EF%B8%8F--custom-prompts),
easily create and set the initial system prompt
- Voice in (**Whisper**) and voice out (**TTS**) _chat / REPL mode_ (`options -cczw`)
- Integration with [awesome-chatgpt-prompts](#-awesome-prompts) and
[Chinese awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh),
[mudler's LocalAI](#localai), [Ollama](#ollama), [Google AI](#google-ai), and [Mistral AI](#mistral-ai).
- _Tiktoken_ for accurate tokenization (optional)
- Colour scheme personalisation, and a configuration file
- Stdin and text file input support
- Shouldโ„ข work on Linux, FreeBSD, MacOS, and [Termux](#termux-users).

### More Features

- [_Generate images_](#%EF%B8%8F-image-generations)
from text input (`option -i`)
- [_Generate variations_](#image-variations) of images
- [_Edit images_](#image-edits),
optionally edit with `ImageMagick` (generate alpha mask)
- [_Transcribe audio_](#-audio-transcriptions-translations)
from various languages (`option -w`)
- _Translate audio_ into English text (`option -W`)
- _Text-to-speeech_ functionality (`option -z`)

## โœจ Getting Started

### โœ”๏ธ Required Packages

- `Bash`
- `cURL`, and `JQ`

### Optional Packages

These are required for specific features.

- `Base64` - Image endpoint, vision models
- `ImageMagick` - Image edits and variations
- `Python` - Tiktoken
- `mpv`/`SoX`/`Vlc`/`FFmpeg`/`afplay`/`play-audio` (Termux) - Play TTS output
- `SoX`/`Arecord`/`FFmpeg`/`termux-microphone-record` - Record input (Whisper)
- `xdg-open`/`open`/`xsel`/`xclip`/`pbcopy`/`termux-clipboard-set` - Open images, set clipboard
- `W3M`/`Lynx`/`ELinks`/`Links` - Dump URL text
- `bat`/`Pygmentize`/`Glow`/`mdcat`/`mdless`/`Pandoc` - Markdown support

### ๐Ÿ’พ Installation

**A.** Download the stand-alone
[`chatgpt.sh` script](https://gitlab.com/fenixdragao/shellchatgpt/-/raw/main/chatgpt.sh)
and make it executable:

wget https://gitlab.com/fenixdragao/shellchatgpt/-/raw/main/chatgpt.sh

chmod +x ./chatgpt.sh

**B.** Or clone this repo:

git clone https://gitlab.com/fenixdragao/shellchatgpt.git

**C.** Optionally, download and set the configuration file
[`~/.chatgpt.conf`](https://gitlab.com/fenixdragao/shellchatgpt/-/raw/main/.chatgpt.conf):

#save configuration template:
chatgpt.sh -FF >> ~/.chatgpt.conf

#edit:
chatgpt.sh -F

# Or
vim ~/.chatgpt.conf

### ๐Ÿ”ฅ Usage Examples ๐Ÿ”ฅ

![Chat cmpls with prompt confirmation](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/chat_cpls_verb.gif)

### ๐Ÿ’ฌ Native Chat Completions

With command line `options -cc`, some properties are set automatically to create a chat bot.
Start a new session in chat mode, and set a different temperature (*gpt-3.5 and gpt-4+ models*):

chatgpt.sh -cc -t0.7

Create **Marv, the sarcastic bot** manually:

chatgpt.sh -60 -cc --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 factual chatbot that reluctantly answers questions with sarcastic responses:'

#### Vision Models (GPT-4-Vision)

To send an `image` / `url` to vision models, start the script and then either
set the image with the `!img` chat command with one or more filepaths / URLs
separated by the operator pipe **|**.

chatgpt.sh -cc -m gpt-4-vision-preview '!img path/to/image.jpg'

Alternatively, set the image paths / URLs at the end of the prompt interactively:

chatgpt.sh -cc -m gpt-4-vision-preview

[...]
Q: In this first user prompt, what can you see? | https://i.imgur.com/wpXKyRo.jpeg

**TIP:** Run chat command `!info` to check model configuration!

**DEBUG:** Set `option -VV` to see the raw JSON request body.

#### Voice In and Out + Chat Completions

๐Ÿ—ฃ๏ธ Chat completion with **Whisper**:

chatgpt.sh -ccw

Chat in Portuguese with voice in and out:

chatgpt.sh -cczw pt

### Chat Mode of Text Completions

When text completions is set for chatting with `option -c`,
some properties are configured automatically to instruct the bot.

chatgpt.sh -c "Hello there! What is your name?"

### ๐Ÿ“œ Text Completions

This is the pure text completions endpoint. It is typically used to
complete input text, such as for completing part of an essay.

One-shot text completion:

chatgpt.sh "Hello there! What is your name?"

**NOTE:** For multiturn, set `option -d`.

A strong Instruction prompt may be needed for the language model to do what is required.

Set an instruction prompt for better results:

chatgpt.sh -d -S 'The following is a newspaper article.' "It all starts when FBI agents arrived at the governor house and"

chatgpt.sh -d -S'You are an AI assistant.' "The list below contain the 10 biggest cities in the w"

#### 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.'

**NOTE:** This example works with _no instruction_ prompt!
An instruction prompt in this mode may interfere with insert completions.

**NOTE:** [Insert mode](https://openai.com/blog/gpt-3-edit-insert)
works with model `gpt-3.5-turbo-instruct`. This endpoint _may deprecate_.

## Markdown

To enable markdown rendering of responses, set command line `option --markdown`,
or run `/md` in chat mode. To render last response in markdown once,
run `//md`.

The markdown option uses `bat` as it has line buffering on by defaults,
however other software is supported.
Set it such as `--markdown=glow` or `/md mdless` on chat mode.

Type in any of the following markdown software as argument to the option:
`bat`, `pygmentize`, `glow`, `mdcat`, `mdless`, or `pandoc`.

## โš™๏ธ 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.

The model steering and capabilities require prompt engineering
to even know that it should answer the questions.

### โŒจ๏ธ Custom Prompts

Set a one-shot instruction prompt with `option -S`:

chatgpt.sh -cc -S 'You are a PhD psycologist student.'

chatgpt.sh -ccS'You are a professional software programmer.'

To create or load a prompt template file, set `option -S` with the
operator dot and the name of the prompt as argument:

chatgpt.sh -cc -S.psycologist

chatgpt.sh -cc -S..software_programmer

This will load the custom prompt, or create it if it does not yet exist.
In the second example, single-shot editing will be skipped after loading
prompt _software_programmer_.

### ๐Ÿ”Œ Awesome Prompts

Set a prompt from [awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts)
or [awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh),
(use with davinci and gpt-3.5+ models):

chatgpt.sh -cc -S /linux_terminal

chatgpt.sh -cc -S /Relationship_Coach

chatgpt.sh -cc -S %ๆ‹…ไปป้›…ๆ€ๅ†™ไฝœ่€ƒๅฎ˜

## ๐Ÿ’ก Notes and Tips

- Run chat commands with either _operator_ `!` or `/`.

- Edit live history entries with command `!hist`, for context injection.

- 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 `/`,
or `//` to have last prompt edited before new request.

## More Examples and Script Modes (Endpoints)

### ๐Ÿ–ผ๏ธ 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 - Canvas Extension

![Displaying Image Edits - Extending the Canvas](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/img_edits.gif)

In this example, a mask is made from the white colour.

#### Inpaint - Fill in the Gaps

![Showing off Image Edits - Inpaint](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/img_edits2.gif)

Adding a bat in the night sky.

### ๐Ÿ”Š 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."

**1.** Generate transcription from voice recording, set Portuguese as the language to transcribe to:

chatgpt.sh -w pt

This also works to transcribe from one language to another.

**2.** Transcribe any language audio input **to Japanese** (_prompt_ should be in
the same language as the input audio language, preferably):

chatgpt.sh -w ja "A job interview is currently being done."

**3.1** Translate English audio input to Japanese, and generate audio output from text.

chatgpt.sh -wz ja "Getting directions to famous places in the city."

**3.2** Also doing it conversely, this gives an opportunity to (manual)
conversation turns of two speakers of different languages. Below,
a Japanese speaker can translate its voice and generate audio in the target language.

chatgpt.sh -wz en "Providing directions to famous places in the city."

**4.** Translate audio file or voice recording from any language to English:

chatgpt.sh -W [audio_file]

chatgpt.sh -W

**NOTE:** Generate phrasal-level timestamps double setting `option -ww`, or `option -WW`.

![Transcribe audio with timestamps](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/chat_trans.png)

## LocalAI

### LocalAI Server

Make sure you have got [mudler's LocalAI](https://github.com/mudler/LocalAI),
server set up and running.

The server can be run as a docker container or a
[binary can be downloaded](https://github.com/mudler/LocalAI/releases).
Check LocalAI tutorials
[Container Images](https://localai.io/basics/getting_started/#container-images),
and [Run Models Manually](https://localai.io/docs/getting-started/manual)
for an idea on how to install, download a model and set it up.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Fiber v2.50.0 โ”‚
โ”‚ http://127.0.0.1:8080 โ”‚
โ”‚ (bound on host 0.0.0.0 and port 8080) โ”‚
โ”‚ โ”‚
โ”‚ Handlers ............. 1 Processes ........... 1 โ”‚
โ”‚ Prefork ....... Disabled PID ..................1 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

### Running

Finally, when running `chatgpt.sh`, set the model name:

chatgpt.sh --localai -cc -m luna-ai-llama2

Setting some stop sequences may be needed to prevent the
model from generating text past context:

chatgpt.sh --localai -cc -m luna-ai-llama2 -s'### User:' -s'### Response:'

Optionally set restart and start sequences for text completions
endpoint (`option -c`), such as `-s'\n### User: ' -s'\n### Response:'`
(do mind setting newlines *\n and whitespaces* correctly).

And that's it!

### Installing Models

Model names may be printed with `chatgpt.sh -l`. A model may be
supplied as argument, so that only that model details are shown.

**NOTE:** Model management (downloading and setting up) must follow
the LocalAI and Ollama projects guidelines and methods.

For image generation, install Stable Diffusion from the URL
`github:go-skynet/model-gallery/stablediffusion.yaml`,
and for audio transcription, download Whisper from the URL
`github:go-skynet/model-gallery/whisper-base.yaml`.

### API Host Configuration

If the host address is different from the defaults, we need editing
the script configuration file `.chatgpt.conf`.

vim ~/.chatgpt.conf

# Or

chatgpt.sh -F

Set the following variable:

# ~/.chatgpt.conf

OPENAI_API_HOST="http://127.0.0.1:8080"

_Alternatively_, set `$OPENAI_API_HOST` on invocation:

OPENAI_API_HOST="http://127.0.0.1:8080" chatgpt.sh -c -m luna-ai-llama2

## Ollama

Visit [Ollama repository](https://github.com/ollama/ollama/),
and follow the instructions to install, download models, and set up
the server.

After having Ollama server running, set `option -O` (`--ollama`),
and the name of the model in `chatgpt.sh`:

chatgpt.sh -cc -O -m llama2

If Ollama server URL is not the defaults `http://localhost:11434`,
edit `chatgpt.sh` configuration file, and set the following variable:

# ~/.chatgpt.conf

OLLAMA_API_HOST="http://192.168.0.3:11434"

## Google AI

Get a free [API key for Google](https://gemini.google.com/) to be able to
use Gemini and vision models. Users have a free bandwidth of 60 requests per minute, and the script offers a basic implementation of the API.

Set the enviroment variable `$GOOGLE_API_KEY` and run the script
with `option --google`, such as:

chatgpt.sh --google -cc -m gemini-pro-vision

*OBS*: Google Gemini vision models _are not_ enabled for multiturn at the API side yet.

To list all available models, run `chatgpt.sh --google -l`.

## Mistral AI

Set up a [Mistral AI account](https://mistral.ai/),
declare the enviroment variable `$MISTRAL_API_KEY`,
and run the script with `option --mistral` for complete integration.

## Arch Linux Users

This project PKGBUILD is available at the
[Arch Linux User Repository (*AUR*)](https://aur.archlinux.org/packages/chatgpt.sh)
to install the software in Arch Linux and derivative distros.

To install the programme from the AUR, you can use an *AUR helper*
like `yay` or `paru`. For example, with `yay`:

yay -S chatgpt.sh

## Termux Users

### Optional Dependencies

For recording audio (Whisper, `option -w`), we recommend `termux-microphone-record`, and
for playing audio (TTS, `option -z`), install `play-audio`.

To set the clipboard, it is required `termux-clipboard-set`.

### Tiktoken

Under Termux, make sure to have your system updated and installed with
`python`, `rust`, and `rustc-dev` packages for building `tiktoken`.

pkg update

pkg upgrade

pkg install python rust rustc-dev

pip install tiktoken

## ๐ŸŽฏ Project Objectives

- Implement nice features from OpenAI API version 1.

- Provide the closest API defaults.

- Let the user customise defaults (as homework).

## โš ๏ธ Limitations

- OpenAI **API version 1** is the focus of the present project implementation.
Not all features of the API will be covered.

- See _BUGS AND LIMITS_ section in the [man page](man/README.md).

- Bash shell truncates input on `\000` (null).

- Bash "read command" may not correctly display input buffers larger than
the TTY screen size during editing. However, input buffers remain
unaffected. Use the text editor interface for big prompt editing.

- Garbage in, garbage out. An idiot savant.

## ๐Ÿ“– Help Pages

Read the online [**man page here**](man/README.md).

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

## ๐Ÿ’ช Contributors

***Many Thanks*** to all that contributed to this project.

[edshamis](https://www.github.com/edshamis)

## Acknowledgements

The following projects are worth remarking.
They were studied during development of this script and used as referencial code sources.

1. [TheR1D's shell_gpt](https://github.com/TheR1D/shell_gpt/)
2. [xenodium's chatgpt-shell](https://github.com/xenodium/chatgpt-shell)
3. [llm-workflow-engine](https://github.com/llm-workflow-engine/llm-workflow-engine)
4. [0xacx's chatGPT-shell-cli](https://github.com/0xacx/chatGPT-shell-cli)
5. [mudler's LocalAI](https://github.com/mudler/LocalAI)
6. [Ollama](https://github.com/ollama/ollama/)
7. [Google Gemini](https://gemini.google.com/)
8. [f's awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts)
9. [PlexPt's awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)


Everyone is [welcome to submit issues, PRs, and new ideas](https://github.com/mountaineerbr/shellChatGPT/discussions/1)!

---


**[The project home is at GitLab](https://gitlab.com/fenixdragao/shellchatgpt)**


_Mirror_




ChatGPT by DALL-E