A python chatGPT cli built with Typer
Chatter is a simple command-line tool that allows you to have a conversation using any of OpenAI's CHAT-GPT models. It also supports reading additional context from a given file to help with generating accurate answers.
- Python 3.9+
- Typer
- OpenAI
- python-dotenv
-
Make sure you have Python 3.9+ installed on your system.
-
Clone the repository. You can do so by running the following command:
git clone git@github.com:mandgie/chatter.git -
Create a virtual environment and activate it:
Example using venv:
python -m venv venv source venv/bin/activate -
Install the required dependencies using pip:
pip install -r requirements.txt -
Create a
.envfile in the same directory as the script and set your OpenAI API key:OPENAI_API_KEY=your_openai_api_key -
Modify the config file by choosing model and path to your python executable, that would be the path to your virtual env. The config file is located at
config.ini.
To use Chatter, simply run the script using the following command:
python chatter.py
After running the script, you'll be prompted to ask your question. If you want to provide additional context from a file, you can do so by providing the file path (absolute or relative) as a parameter, like this:
python chatter.py --file_path path/to/your/context_file.txt
Chatter now supports providing additional context through the context_string optional argument. This argument is helpful when you want to provide extra information to help GPT generate accurate answers without needing to read it from a file.
For example:
python chatter.py --context-string "Your context string here"
python chatter.py --context-string "$(ls)"
Once you've asked a question, the script will return an answer from GPT. You can continue asking questions until you're satisfied with the answer.
To exit the script, simply input "yes" when asked if you're satisfied with the answer, or press CTRL+C.
To create a symlink to execute the CLI with the word "chatter" on macOS, follow the steps below:
-
Run the following command to create a symlink called "chatter":
ln -s ./launcher.sh /usr/local/bin/chatter -
Now you can start the CLI anywhere by using the word "chatter".
chatter
If you encounter any rate-limiting issues, the script will automatically retry until the maximum number of retries is reached (default is 5). If the maximum number of retries is reached, the script will exit with an error message.
Thank you for considering contributing to this project! I appreciate any help and suggestions that can make this tool even better. If you would like to contribute, here are a few guidelines:
- Fork the repository on GitHub and clone your fork to your local machine.
- Create a new branch for your feature or bugfix.
- Commit your changes to the new branch, following the commit message guidelines.
- Push your changes to your fork.
- Create a pull request, describing the changes and their purpose.