ChatGPT CLI for Linux is a Bash shell script designed to interact with OpenAI's ChatGPT API directly from the Linux terminal. This lightweight and efficient CLI tool allows users to generate and render Markdown content using ChatGPT, with the added convenience of viewing the formatted output within the terminal. It's built for Linux users seeking a straightforward way to leverage ChatGPT without the need for a complex setup or a graphical interface.
- Generate Markdown content using ChatGPT
- Render Markdown beautifully in the terminal with
glow - Simple and easy-to-use CLI interface
- Contextual chat conversations
- No Python dependencies; purely Bash with minimal external tools
curl: Used to make requests to the OpenAI API.jq: Processes JSON data, including the responses from OpenAI's API.glow: Renders Markdown content in the terminal.
To install the required dependencies (curl, jq) and set up ChatGPT CLI for Linux, follow these steps:
-
Install curl and jq: Open a terminal and run the following command:
sudo apt update && sudo apt install curl jq -y -
Install glow: For the most up-to-date installation instructions for
glow, please refer to the Glow GitHub page.glowallows for the Markdown rendered by the script to be beautifully displayed in the terminal.
To use ChatGPT CLI for Linux, an OpenAI API key is required. Follow the steps below to create an account, add funds, and obtain your API key:
-
Create an OpenAI Account:
- Visit OpenAI's Signup Page and follow the instructions.
-
Add Funds for API Use:
- API usage is not included with the standard ChatGPT subscription and requires pre-credited funds.
- Log in to OpenAI Platform, navigate to Billing, and follow the instructions to add a payment method and credit your account.
-
Generate an API Key:
- Go to API Keys section in your OpenAI account and click "New API Key".
- Securely store the generated API key for use with the CLI tool.
After installing the dependencies and configuring your OpenAI API key, you need to ensure the script is executable and set up your environment for using the script.
Before running the script, make it executable by navigating to the directory containing chatgpt-cli.sh and running:
chmod +x chatgpt-cli.shWithin the script, there are two variables you may want to adjust:
-
API_KEY: This is where you replace the placeholder with your actual OpenAI API key for authenticating your requests. This key enables access to the ChatGPT API. -
MODEL(optional): By default, the script usesgpt-3.5-turboas the model. OpenAI provides various models, includinggpt-4andgpt-4-turbo, which you might prefer for different functionalities or capabilities. For a comprehensive list of models and their descriptions, refer to the OpenAI Model Documentation. If you wish to use a different model, adjust theMODELvariable in the script accordingly.
With the API key set and the script made executable, you can interact with ChatGPT from your terminal:
./chatgpt-cli.shEnsure your API key is correctly set in the script or as an environment variable for secure access. Follow the on-screen prompts to input your queries. You'll receive Markdown-formatted responses from ChatGPT, which are rendered directly in your terminal via glow. This allows for viewing formatted text, including code blocks and other Markdown elements, in a clear and readable format.
Contributions to ChatGPT CLI for Linux are welcome! If you have suggestions, improvements, or bug fixes, feel free to fork the repository, make your changes, and submit a pull request.
Copyright (c) 2024 Jonathan Geller
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
