ChatGPT CLI. Streaming text. Has memory.
Here's an alternative with a bunch of features: https://github.com/TheR1D/shell_gpt
-
Clone the repository
-
Install the required dependencies
$ python3 -m pip install . --user
-
If using openai, set your OpenAI API key. E.g.
export OPENAI_API_KEY="123"
.You can obtain your API key from the OpenAI website.
-
Optionally, symlink the provided
chatgpt
script to your path.$ ln -s "$PWD/chatgpt" "$HOME/bin" # assuming ~/bin is in PATH
You can run the ChatGPT CLI by executing the Python script with a query as an argument. For example:
$ # The included 'chatgpt' script will do per-directory chat history.
$ chatgpt hi what is up # ...or
$ chatgpt "hi what's up"
$ chatgpt -c 'the `-c` first clears history, then sends this as usual (without history).'
The query will be used as a user message in the conversation with the model. The program will stream the response from the model and display it on the terminal.
You can also clear the conversation history by passing an empty query:
$ chatgpt # Clears history
ai/openai.py contains env variables for request customization, e.g. model name.
It sends a series of messages as input to the API, including system messages, user messages, and assistant messages. The assistant message contains the response from the model.
The conversation history is stored in a JSON file in the cache directory, which can be customized using the XDG_CACHE_DIR
(usually ~/.cache
) environment variable. The program streams the response from the model and displays it on the terminal. It also handles interrupts (SIGINT) to save the conversation history before exiting.
If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository: https://github.com/your_username/your_repository
- Don't know if works on Windows.
- Some prompts fail at escaping and crash
- Running in a shell with an altered env sometimes fails for reasons
such as modified LD_PRELOAD (or some other c/c++ junk?)
e.g. in a
nix shell
. - Prompts for shell command querying (e.g. ctrl-q in shell) don't save in shell history
The interactive mode responses can't be cut off with ctrl-c.
This program is released under the MIT License. See the LICENSE file for more details.
This readme was written by chatgpt