This is one way to implement a ChatGPT-like interface for your shell/console using Python.
Note: This assumes you already have Python. Check the official Python website if you don't have it.
-
If you haven't already done so, setup your OpenAI API key (see OpenAI's Quickstart tutorial). Note that you need to be a paying customer to access GPT-4. Install the OpenAI Python library and other dependencies with
pip install --upgrade openai requests validators
. -
Download the script into your preferred location (or clone the repository to your local machine).
-
Open your terminal and navigate to the script directory or repository (e.g.,
cd /path/to/script/directory
in Linux/macOS). -
Input
python chatbot.py
to run the chatbot. See sample runs here.
When I decided on a name, I didn't realize there were other console versions out there named ConsoleGPT (or Console-GPT), but I stuck with the name despite redundancy as it still felt the most fitting.
Some features of this implementation that may or may not be shared by other versions:
- The interface is on the structured side presentation-wise, mostly because of all the
print
statements. - You can choose between the latest OpenAI models (assuming you have access), give custom instructions, name the chatbot, specify the model temperature (higher = more creative but less coherent), and save/load chat history files with their settings.
- The Python code reflects recent updates in how OpenAI models should be accessed (e.g., you should now be using
chat.completions.create
instead ofChatCompletion.create
).
Feel free to message me (@cvee) through Discord or email me at [email protected].
This work is licensed under the MIT License. See LICENSE for more details.