Trivial implementation of a ChatGPT interface in shell, mainly for personal use or as a reference for other implementations.
The use of clipboard is only supported in macOS.
Basic usage is with the chatgpt.py
script. You can run it in interactive mode (multiple rounds of conversation), or in oneshot mode (one round of conversation w/ or w/o history).
$ python chatgpt.py --mode interactive # interactive mode, use "!help" for help
$ python chatgpt.py --mode oneshot --type chat --prompt "Who are you? What are you doing here?"
$ python chatgpt.py --mode oneshot --type search --prompt "Best resorts in the world"
If you use macOS with vscode, the simpler run.sh
script is recommended for oneshot interaction.
Results will be copied to clipboard and shown in vscode automatically.
In one-shot mode, only ctx_chat
considers the previous context, which is suitable for follow-up questions.
$ ./run.sh chat "Who are you? What are you doing here?"
$ ./run.sh search "Best resorts in the world"
$ ./run.sh ctx_chat "Talk about one of them in detail." # follow up with the previous context
# copy "I don't konw waht I am talking about" to clipboard, then
$ ./run.sh revise
It keeps a local copy of all the conversations in a sqlite3 database.
You can view bill in hour, day, week, month, and all time.
$ python chatgpt.py --mode bill
You can export the database to csv/markdown files with chat history in hour, day, week, month, and all time.
$ python chatgpt.py --mode export
Only tested on macOS
pip install openai
- Correct
OPENAI_API_KEY
environment variable set, get it from here. You should have a paid account to use the API.
Download the Workflow and import it to Alfred.
- Make sure you can run
run.sh
from the terminal - Set
OPENAI_API_KEY
andCAI_PATH
(path to the repo) in Alfred Workflow (Alfred does not load environment variables from.bashrc
or.zshrc
) - Replace the
python
(andcode
) command inrun.sh
with the absolute path to your python executable, e.g./usr/local/bin/python3.8
, obtained bywhich python
in the terminal
With a simple Alfred Workflow (Keyword -> Run Script) set up, you can do this