The gpt-shell.py
script is a robust Python command-line interface that harnesses the power of OpenAI’s GPT models to offer insightful suggestions for Linux shell commands. Whether you input a specific command or describe a task, the application will generate an appropriate command as interpreted by the selected GPT model.
Leveraging modules like openai
, tiktoken
, and prompt_toolkit
, the script communicates with the chosen GPT model through the OpenAI API and enhances user interaction. For the script to function, an API key, set as an environment variable, is a necessity.
Designed for terminal environment operation, this script provides a user-friendly system prompt for input. It shines in its ability to consolidate multi-step commands into a single-line command. In addition, it includes an analysis of the command’s output performed by the GPT model, providing a comprehensive execution explanation along with the suggested command.
Installation
- Clone the repository to your local machine.
- Install the required dependencies by running
pip install -r requirements.txt
. - Set your OpenAI API key as an environment variable
export OPENAI_API_KEY='your-api-key'
.
Usage
- Open a terminal and navigate to the directory where
gpt-shell.py
is located. - Run the script by typing
python gpt-shell.py
and pressing enter. - Follow the system