Awesome
shellChatGPT
Shell wrapper for OpenAI's ChatGPT, DALL-E, Whisper, and TTS. Features LocalAI, Ollama, Gemini, Mistral, and Groq integration.
Chat completions with streaming by defaults.
<details> <summary>Expand Markdown Processing</summary>Markdown rendering of chat response (optional).
</details> <details> <summary>Expand Text Completions</summary>In pure text completions, start by typing some text that is going to be completed, such as news, stories, or poems.
</details> <details> <summary>Expand Insert Mode</summary>Add the insert tag [insert]
where it is going to be completed.
Mistral code models
work well with the insert / fill-in-the-middel (FIM) mode!
If no suffix is provided, it works as plain text completions.
Index
<details> <summary>Click to expand!</summary>-
- 3.1 Required Packages
- 3.2 Optional Packages
- 3.3 Installation
- 3.4 Usage Examples
- 3.5 Native Chat Completions
- 3.6 Chat Mode of Text Completions
- 3.7 Text Completions
-
- 6.1 Custom Prompts
- 6.2 Awesome Prompts
-
- 7.1 Bash
- 7.2 Zsh
- 7.3 Troubleshoot
-
- 10.1 LocalAI
- 10.1.1 LocalAI Server
- 10.1.2 Tips
- 10.1.3 Running the shell wrapper
- 10.1.4 Installing Models
- 10.1.5 Host API Configuration
- 10.2 Ollama
- 10.3 Google AI
- 10.4 Mistral AI
- 10.5 Groq
- 10.6 Anthropic
- 10.1 LocalAI
-
- 12.1 Dependencies
- 12.2 TTS Chat - Removal of Markdown
- 12.3 Tiktoken
- 12.4 Troubleshoot
๐ Features
- Text and chat completions with gpt-4o and gtp-4-vision support
- Text editor interface, Bash readline, and cat input modes
- Markdown rendering support in response
- Preview, and regenerate responses
- Manage sessions, print out previous sessions
- Instruction prompt manager, easily create and set the initial system prompt
- Voice in (Whisper) plus voice out (TTS) chat mode (
options -cczw
) - Integration with mudler's LocalAI, Ollama, Google AI, Mistral AI, Groq, and Anthropic
- Support for awesome-chatgpt-prompts and Chinese awesome-chatgpt-prompts-zh
- Command line completion and file picker dialogs for a smoother experience ๐ป
- Colour scheme personalisation ๐จ and a configuration file
- Tiktoken for accurate tokenization (optional)
- Stdin and text file input support
- Shouldโข work on Linux, FreeBSD, MacOS, and Termux
- Fast shell code for a responsive experience! โก๏ธ
โจ Getting Started
โ๏ธ Required Packages
Bash
<!-- [Ksh93u+](https://github.com/ksh93/ksh), Bash or Zsh -->cURL
, andJQ
Optional Packages
Packages required for specific features.
<details> <summary>Click to expand!</summary>Base64
- Image endpoint, vision modelsPython
- Modules tiktoken, markdown, bs4ImageMagick
/fbida
- Image edits and variationsSoX
/Arecord
/FFmpeg
- Record input (Whisper)mpv
/SoX
/Vlc
/FFplay
/afplay
- Play TTS outputxdg-open
/open
/xsel
/xclip
/pbcopy
- Open images, set clipboardW3M
/Lynx
/ELinks
/Links
- Dump URL textbat
/Pygmentize
/Glow
/mdcat
/mdless
- Markdown supporttermux-api
/termux-tools
/play-audio
- Termux systempoppler
/gs
/abiword
/ebook-convert
/LibreOffice
- Dump PDF or Doc as textdialog
/kdialog
/zenity
/osascript
/termux-dialog
- File picker
๐พ Installation
A. Download the stand-alone
chatgpt.sh
script
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
:
#save configuration template:
chatgpt.sh -FF >> ~/.chatgpt.conf
#edit:
chatgpt.sh -F
# Or
vim ~/.chatgpt.conf
<!--
### ๐ฅ Usage
- Set your [OpenAI GPTChat key](https://platform.openai.com/account/api-keys)
with the environment variable `$OPENAI_API_KEY`, or set `option --api-key [KEY]`, or set the configuration file.
- Just write your prompt as positional arguments after setting options!
- 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.
-->
๐ฅ Usage Examples ๐ฅ
๐ฌ 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.'
<!--
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "Who wrote 'Romeo and Juliet'?"}, {"role": "assistant", "content": "Oh, just some guy named William Shakespeare. Ever heard of him?"}]}
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "How far is the Moon from Earth?"}, {"role": "assistant", "content": "Around 384,400 kilometers. Give or take a few, like that really matters."}]}
-->
<!-- https://platform.openai.com/docs/guides/fine-tuning/preparing-your-dataset -->
Load the unix instruction file ("unix.pr") for a new session. The command line syntaxes below are all aliases:
chatgpt.sh -cc ..unix
chatgpt.sh -cc..unix
chatgpt.sh -cc -..unix
chatgpt.sh -cc -S ..unix
<!--
In this case, the custom prompt will be loaded, and the history will be recorded in the corresponding "unix.tsv" file at the cache directory.
-->
To only chage the history file that the session will be recorded,
set the first positional argument in command line with the operator forward slash "/
"
and the name of the history file (defaults to the /session
command).
chatgpt.sh -cc /test
chatgpt.sh -cc /stest
chatgpt.sh -cc "/session test"
<!--
The command below starts a chat session, loads the "unix" instruction, and changes to the defaults "chatgpt.tsv" history.
chatgpt.sh -cc..unix /current
chatgpt.sh -cc -S "..unix" /session current
-->
Load an older session from the current (defaults) history file.
chatgpt.sh -cc /sub
chatgpt.sh -cc /.
chatgpt.sh -cc /fork.
chatgpt.sh -cc "/fork current"
In chat mode, simple run !sub
or the equivalent command !fork current
.
To load an older session from a history file that is different from the defaults, there are some options.
Change to it with command !session [name]
.
To copy a previous session, run /sub
or /grep [regex]
to load that
session and resume from it.
Print out last session, optionally set the history name:
chatgpt.sh -P
chatgpt.sh -P /test
<!-- Mind that `option -P` heads `-ccdrR`! -->
<!-- The same as `chatgpt.sh -HH` -->
Vision and Multimodal Models
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.
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:
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 -V
to see the raw JSON request body.
Text, PDF, Doc, and URL Dumps
To make an easy workfow, the user may add a filepath or URL to the end of the prompt. The file is then read and the text content appended to the user prompt. This is a basic text feature that works with any model.
chatgpt.sh -cc
[...]
Q: What is this page: https://example.com
Q: Help me study this paper. ~/Downloads/Prigogine\ Perspective\ on\ Nature.pdf
In the second example, the PDF will be dumped as text.
For PDF text dump support, poppler/abiword
is required.
For doc and odt files, LibreOffice
is required.
See the Optional Packages section.
Also note that file paths containing white spaces must be blackslash-escaped.
File Picker and Shell Dump
The /pick
command opens a file picker (usually a command-line
file manager). The selected file's path will be appended to the
current prompt in editing mode.
The /pick
and /sh
commands may be run when typed at the end of
the current prompt, such as [PROMPT] /sh
, which opens a new
shell instance to execute commands interactively. The output of these
commands is appended to the current prompt.
When the /pick
command is run at the end of the prompt, the selected
file path is appended instead.
File paths that contain white spaces need backslash-escaping in some functions.
Voice In and Out + Chat Completions
๐ฃ๏ธ Chat completion with audio in and out (Whisper plus TTS):
chatgpt.sh -ccwz
Chat in Portuguese with Whisper and set onyx as the TTS voice:
chatgpt.sh -ccwz -- pt -- onyx
Chat mode provides a conversational experience, prompting the user to confirm each step.
For a more automated execution, set option -v
,
and -vv
for hands-free experience (live chat)
(detect silence, experimental), such as:
chatgpt.sh -cc -w -z -v
chatgpt.sh -cc -w -z -vv
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?"
<!-- **TIP**: Set _-vv_ to have auto sleep for reading time of last response,
and less verbose in voice input chat! *Only without option -z!* -->
<!--
Generate some unexpected use cases if chatgpt.sh.
Certainly! Here are some unexpected use cases of the `chatgpt.sh` script:
1. Creative Writing Assistant: Use the script to generate story prompts or brainstorm ideas for your creative writing projects.
2. Virtual Therapist: Have a chat session with the script as a virtual therapist, sharing your thoughts and feelings.
3. Language Learning Partner: Practice your language skills by having conversations with the script in your target language.
4. Coding Assistance: Use the script to help you with coding tasks by providing code snippets or answering programming-related questions.
5. Artistic Collaboration: Collaborate with the script to co-create art pieces, coming up with unique concepts and ideas.
6. Songwriting Inspiration: Get inspired by having a chat session with the script and use its responses as prompts for songwriting.
7. Historical Simulation: Have a conversation with the script as a historical figure or simulate historical events by interacting with the script.
8. Technical Support: Use the script to troubleshoot technical issues or provide instructions for using specific software or tools.
9. Game Master Assistant: Use the script to assist you in running tabletop role-playing game sessions by generating NPCs, locations, and plot ideas.
10. Virtual Travel Guide: Have a chat session with the script to get travel recommendations, learn about different destinations, and plan your next trip.
These unexpected use cases demonstrate the versatility of the `chatgpt.sh` script and how it can be utilized beyond its traditional applications. Have fun exploring and discovering new ways to interact with it!
-->
๐ 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
(or -qq
for multiturn) 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
works with model instruct models
.
Mistral AI has a nice FIM (fill-in-the-middle) endpoint that works
with code
models and is really good!
Script Help Assistant
If you have got a question about the script itself and how to set it up, there is a built-in assistant (much like M$ Office Clipper).
While in chat mode, type the command /help [question]
, in which the question
is related to script features and your current chat settings, and how
you can change them or invoke the script with the right syntax!
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
, or mdless
.
โ๏ธ 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.
<!-- **NOTE:** Heed your own instruction (or system prompt), as it may refer to both *user* and *assistant* roles. -->โจ๏ธ 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 the first positional argument
as .prompt_name
or ..prompt_name
.
In the second case, load the prompt as instruction
without a single-shot editing.
chatgpt.sh -cc .psycologist
chatgpt.sh -cc ..software_programmer
Alternatively, set option -S
with the operator and the name of
the prompt as an 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.
Please note and make sure to backup your important custom prompts!
They are located at "~/.cache/chatgptsh/
" with the extension ".pr".
๐ Awesome Prompts
Set a prompt from awesome-chatgpt-prompts or 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 '%ๆ
ไปป้
ๆๅไฝ่ๅฎ'
<!--
_TIP:_ When using Ksh, press the up arrow key once to edit the _full prompt_
(see note on [shell interpreters](#shell-interpreters)).
-->
Shell Completion
This project includes shell completions to enhance the user command-line experience.
Bash
Install following one of the methods below.
System-wide
sudo cp comp/bash/chatgpt.sh /usr/share/bash-completion/completions/
User-specific
mkdir -p ~/.local/share/bash-completion/completions/
cp comp/bash/chatgpt.sh ~/.local/share/bash-completion/completions/
Visit the bash-completion repository.
Zsh
Install at the system location
sudo cp comp/zsh/_chatgpt.sh /usr/share/zsh/site-functions/
User-specific location
To set user-specific completion, make sure to place the completion
script under a directory in the $fpath
array.
The user may create the ~/.zfunc/
directory, for example, and
add the following lines to her ~/.zshrc
:
[[ -d ~/.zfunc ]] && fpath=(~/.zfunc $fpath)
autoload -Uz compinit
compinit
Make sure compinit
is run after setting $fpath
!
Visit the zsh-completion repository.
Troubleshoot Shell
Bash and Zsh completions should be active in new terminal sessions.
If not, ensure your ~/.bashrc
and ~/.zshrc
source
the completion files correctly.
๐ก 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 Script Modes
๐ผ๏ธ 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
In this example, a mask is made from the white colour.
Inpaint - Fill in the Gaps
<!-- ![Inpaint, steps](https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/img_edits_steps.png) -->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
To retry with the last microphone recording saved in the cache, set
audio_file as last
or retry
.
NOTE: Generate phrasal-level timestamps double setting option -ww
or option -WW
.
For word-level timestamps, set option -www
or -WWW
.
Service Providers
LocalAI
LocalAI Server
Make sure you have got mudler's LocalAI, server set up and running.
The server can be run as a docker container or a binary can be downloaded. Check LocalAI tutorials Container Images, and Run Models Manually 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 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Tips
1. Download a binary of localai
for your system from Mudler's release GitHub repo.
2. Run localai run --help
to check comamnd line options and environment variables.
3. Set up $GALLERIES
before starting up the server:
export GALLERIES='[{"name":"localai", "url":"github:mudler/localai/gallery/index.yaml"}]' #defaults
export GALLERIES='[{"name":"model-gallery", "url":"github:go-skynet/model-gallery/index.yaml"}]'
export GALLERIES='[{"name":"huggingface", "url": "github:go-skynet/model-gallery/huggingface.yaml"}]'
<!-- broken huggingface gallery: https://github.com/mudler/LocalAI/issues/2045 -->
4. Install the model named phi-2-chat
from a yaml
file manually, while the server is running:
curl -L http://localhost:8080/models/apply -H "Content-Type: application/json" -d '{ "config_url": "https://raw.githubusercontent.com/mudler/LocalAI/master/embedded/models/phi-2-chat.yaml" }'
Running the shell wrapper
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
.
Host API 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, 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 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, so we hack it.
To list all available models, run chatgpt.sh --google -l
.
Mistral AI
Set up a Mistral AI account,
declare the enviroment variable $MISTRAL_API_KEY
,
and run the script with option --mistral
for complete integration.
Groq
Sign in to Groq.
Create a new API key or use an existing one to set
the environmental variable $GROQ_API_KEY
.
Run the script with option --groq
.
Currently, llamma3.1 models are available at lightening speeds!
<!-- ### Grok Visit [Grok](https://x.ai/) and check the [eligible countries and regions](https://x.ai/regions). -->Anthropic
Sign in to Antropic AI.
Create a new API key or use an existing one to set
the environmental variable $ANTHROPIC_API_KEY
.
Run the script with option --anthropic
or --ant
.
Check the Claude-3 models! Run the script as:
chatgpt.sh --anthropic -cc -m claude-3-5-sonnet-20240620
The script also works on text completions with models such as
claude-2.1
, although the API documentation flags it as deprecated.
Try:
chatgpt.sh --ant -c -m claude-2.1
<!--
## ๐ Environment
- Set `$OPENAI_API_KEY` with your OpenAI API key.
- Optionally, set `$CHATGPTRC` with path to the configuration file (run
`chatgpt.sh -FF` to download a template configuration file.
Defaults location = `~/.chatgpt.conf`.
-->
<!--
## ๐ 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.
Although it should be noted that I test the script under Ksh and Zsh,
and it is almost never tested under Bash, but so far, Bash seems to be
a little more polished than the other shells [AFAIK](https://github.com/mountaineerbr/shellChatGPT/discussions/13),
specially with interactive features.
Ksh truncates input at 80 chars when re-editing a prompt. A workaround
with this script is to press the up-arrow key once to edit the full prompt.
Ksh will mangle multibyte characters when re-editing input. A workaround
is to move the cursor and press the up-arrow key once to unmangle the input text.
Zsh cannot read/load a history file in non-interactive mode,
so only commands of the running session are available for retrieval in
new prompts (with the up-arrow key).
See [BUGS](https://github.com/mountaineerbr/shellChatGPT/tree/main/man#bugs)
in the man page.
-->
<!-- [Ksh93u+](https://github.com/ksh93/ksh) (~~_avoid_ Ksh2020~~), -->
Arch Linux Users
This project PKGBUILD is available at the Arch Linux User Repository (AUR) 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
<!--
There is a [*PKGBUILD*](pkg/PKGBUILD) file available to install
the script and documentation at the right directories
in Arch Linux and derivative distros.
This PKGBUILD generates the package `chatgpt.sh-git`.
Below is an installation example with just the PKGBUILD.
cd $(mktemp -d)
wget https://gitlab.com/fenixdragao/shellchatgpt/-/raw/main/pkg/PKGBUILD
makepkg
pacman -U chatgpt.sh-git*.pkg.tar.zst
-->
Termux Users
Dependencies Termux
Install the Termux
and Termux:API
apps from the F-Droid store.
Give all permissions to Termux:API
in your phone app settings.
We reccommend to also install sox
, ffmpeg
, pulseaudio
, imagemagick
, and vim
(or nano
).
Remember to execute termux-setup-storage
to set up access to the phone storage.
In Termux proper, install the termux-api
and termux-tools
packages (pkg install termux-api termux-tools
).
When recording audio (Whisper, option -w
),
if pulseaudio
is configured correctly,
the script uses sox
, ffmpeg
or other competent software,
otherwise it defaults to termux-microphone-record
Likewise, when playing audio (TTS, option -z
),
depending on pulseaudio
configuration use sox
, mpv
or
fallback to termux wrapper playback (play-audio
is optional).
To set the clipboard, it is required termux-clipboard-set
from the termux-api
package.
TTS Chat - Removal of Markdown
Markdown in TTS input may stutter the model audio generation a little.
If python
modules markdown
and bs4
are available, TTS input will
be converted to plain text. As fallback, pandoc
is used if present
(chat mode only).
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
Troubleshoot Termux
In order to set Termux access to recording the microphone and playing audio
(with sox
and ffmpeg
), follow the instructions below.
A. Set pulseaudio
one time only, execute:
pulseaudio -k
pulseaudio -L "module-sles-source" -D
B. To set a permanent configuration:
- Kill the process with
pulseaudio -k
. - Add
load-module module-sles-source
to one of the files:~/.config/pulse/default.pa /data/data/com.termux/files/usr/etc/pulse/default.pa
- Restart the server with
pulseaudio -D
.
C. To create a new user ~/.config/pulse/default.pa
, you may start with the following template:
#!/usr/bin/pulseaudio -nF
.include /data/data/com.termux/files/usr/etc/pulse/default.pa
load-module module-sles-source
Acess file
To access your Termux files using Android's file manager, install a decent file manager such as FX File Explorer
from a Play Store and configure it, or run the following command in your Termux terminal:
am start -a android.intent.action.VIEW -d "content://com.android.externalstorage.documents/root/primary"
Source: https://www.reddit.com/r/termux/comments/182g7np/where_do_i_find_my_things_that_i_downloaded/
<!-- Users of Termux may have some difficulty compiling the original Ksh93 under Termux. As a workaround, use Ksh emulation from Zsh. To make Zsh emulate Ksh, simply add a symlink to `zsh` under your path with the name `ksh`. After installing Zsh in Termux, create a symlink with: ```` ln -s /data/data/com.termux/files/usr/bin/zsh /data/data/com.termux/files/usr/bin/ksh ```` -->๐ฏ Project Objectives
-
Implement nice features from
OpenAI API version 1
. -
Provide the closest API defaults.
-
Let the user customise defaults (as homework).
-
Premiรจre of
chatgpt.sh version 1.0
should occur at the time when OpenAI launches its next major API version update.
โ ๏ธ Limitations
-
OpenAI API version 1 is the focus of the present project implementation. Not all features of the API will be covered.
-
This project doesn't support "Function Calling" or "Structured Outputs".
-
We aren't very much keen on implementing video capabilities.
-
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.
-
The script logic resembles a bowl of spaghetti code after a cat fight.
-
Garbage in, garbage out. An idiot savant.
-
See BUGS AND LIMITS section in the man page.
Bug report
Please leave bug reports at the GitHub issues page.
๐ Help Pages
Read the online man page here.
Alternatively, a help page snippet can be printed with chatgpt.sh -h
.
Also check the built-in Script Help Assistant.
๐ช Contributors
Many Thanks to all that contributed to this project.
Acknowledgements
The following projects are worth remarking. They were studied during development of this script and used as referencial code sources.
- TheR1D's shell_gpt
- xenodium's chatgpt-shell
- llm-workflow-engine
- 0xacx's chatGPT-shell-cli
- mudler's LocalAI
- Ollama
- Google Gemini
- Groq
- Antropic AI
- f's awesome-chatgpt-prompts
- PlexPt's awesome-chatgpt-prompts-zh
Everyone is welcome to submit issues, PRs, and new ideas!
<br />
https://gitlab.com/fenixdragao/shellchatgpt
<br />Mirror
<br /> <a href="https://gitlab.com/fenixdragao/shellchatgpt"><p align="center"> <img width="128" height="128" alt="ChatGPT by DALL-E, link to GitLab Repo" src="https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/dalle_out20b.png"> </p></a> <!-- ## Version History This is the version number history recorded throughout the script evolution over time. The lowest record is **0.06.04** at _3/Mar/2023_ and the highest is **0.57.01** at _May/2024_. <br /> <a href="https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/chatgpt.sh_version_evol.png"><p align="center"> <img width="386" height="290" alt="Graph generated by a list of sorted version numbers and through GNUPlot." src="https://gitlab.com/mountaineerbr/etc/-/raw/main/gfx/chatgpt.sh_version_evol_small.png"> </p></a> --> <!-- Graph generated by the following ridiculously convoluted command for some fun! ``` git rev-list --all | xargs git grep -e by\ mountaineerbr | grep chatgpt\.sh: | while IFS=:$IFS read com var ver; do ver=${ver##\# v}; printf "%s %s\\n" "$(git log -1 --format="%ci" $com)" "${ver%% *}"; done | uniq | sed 's/ /T/; s/ //' | sed 's/\(.*\.\)\([0-9]\)\(\..*\)/\10\2\3/' | sed 's/\(.*\.\)\([0-9]\)$/\10\2/' | sed 's/\(.*\..*\)\.\(.*\)/\1\2/' | sort -n | grep -v -e'[+-]$' -e 'beta' | gnuplot -p -e 'set xdata time' -e 'set timefmt "%Y-%m-%dT%H:%M:%S%Z"' -e 'plot "-" using 1:2 with lines notitle' ``` --> <!-- # How many functions are there in the script and their function code line numbers (v0.61.3): ``` % grep -ce\^function bin/chatgpt.sh 22:03 126 % sed -n '/^function /,/^}/ p ' ~/bin/chatgpt.sh | test.sh | SUM Sum : 2477 lines in functions Min : 1 line Max : 473 lines Average : 21 lines per func Median : 7 lines per func Values : 118+8 functions (one-liner functions not computed) ``` --> <!-- ## Star History [![Star History Chart](https://api.star-history.com/svg?repos=mountaineerbr/shellChatGPT&type=Date)](https://star-history.com/#mountaineerbr/shellChatGPT&Date) --> <!-- Estimated value of the project if commissioned: ~$1500 over one year (2023-2024). -->