mods for LLM interface in the shell

28 March 2024

mods from Charm is a very cozy way to use LLMs (ChatGPT and the like) in the shell — just make sure your API key is set as an environment variable (e.g. OPENAI_API_KEY) and the prompt is the first argument e.g.

mods 'Please suggest some popular films from the 1980s'

Why bother? It looks nice, it keeps your history with hashes (like a git commit log), and it’s extremely handy to ask programming queries/for examples directly in the shell. mods -l to show history, mods -s='hash' to view from the hash.

Mods can also have input piped in which means we can also do prompt-stuffing with pbpaste / pbcopy.

Note: on MacOS pbpaste / pbcopy are build-in. On Linux the below aliases can be used for the same effect:

alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'

Syntax for combining on the shell:

echo 'This is the string to stuff' | pbcopy
(echo 'Prompt'; pbpaste)
Prompt
This is the string to stuff

Actually mods makes it even easier than this because it will append anything piped in to the prompt provided as the first argument.

e.g. if you want a portion of a webpage summarising and you have just copied the text you want:

pbpaste | mods 'Please summarise the below\n---\n'

How to install

To install in Debian/Ubuntu/Pop!_OS

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
sudo apt update && sudo apt install mods

To install on MacOS

brew install charmbracelet/tap/mods

Refs

mods on github: https://github.com/charmbracelet/mods
… features page: https://github.com/charmbracelet/mods/blob/main/features.md
charm http://charm.sh/