A simple command-line interface to interact with OpenAI's ChatGPT. You can start new conversations, continue historic ones, or use prompts from a file with this flexible script.
-
Prerequisites:
- You need to have
curlandjqinstalled on your system. - An OpenAI API key is required. If you don't have one, you can get it from the OpenAI API website.
- You need to have
-
Clone or Download the Script: Download the script and make it executable:
curl -O https://example.com/path/to/chatgpt-cli.sh chmod +x chatgpt-cli.sh
-
Set Your OpenAI API Key: Set your API key in the script, or alternatively, export it as an environment variable:
export PERSONAL_OPENAI_API_KEY="your-api-key-here"
-
Ensure the Context Directory Exists: The script will create a
contextsdirectory in the same folder where it is executed. If it's missing, it will be created automatically.
Usage: ./chatgpt-cli.sh [options]
Options:
-p "Prompt" Specify the prompt for ChatGPT.
-f "File Path" Specify a file containing the prompt.
-c "Context Path" Specify the path to a historic context file.
-n Start a new context (ignore any existing context).
-h Display this help message../chatgpt-cli.sh -p "What is quantum computing?" -nThis will create a new context based on the provided prompt and start a new conversation.
./chatgpt-cli.sh -f "./prompt.txt" -nThis reads the prompt from the specified file (prompt.txt) and starts a new context.
./chatgpt-cli.sh -c "./contexts/quantum_conversation.json" -p "What are the practical applications of quantum computing?"This continues a conversation based on an existing context file, adding the new prompt to the ongoing conversation.
./chatgpt-cli.sh -f "./prompt.txt" -nIf you use the -f flag to read a prompt from a file, the script will create a new context file based on the first 50 characters of the prompt (with spaces replaced by underscores).
-
Start New Context (
-n):- Start a fresh conversation and ignore any existing context.
- The context file will be named based on the first 50 characters of the prompt (or a custom name if specified).
-
Prompt from Command Line (
-p):- You can pass the prompt directly as a command-line argument.
-
Prompt from File (
-f):- Instead of typing the prompt, you can pass a file containing the prompt text.
-
Continue Historic Context (
-c):- Resume a previous conversation by providing the path to an existing context file.
-
Context Management:
- All conversation contexts are stored in the
contexts/directory. - Each context is saved as a JSON file, ensuring you can continue conversations over time.
- All conversation contexts are stored in the
-
Easy Integration:
- Designed to be simple and flexible, you can integrate this script into your own projects or use it directly from the terminal.
-
Error: "File does not exist":
- Ensure that the file path you provided exists, and the script has permission to read the file.
-
Error: "Prompt cannot be empty":
- Make sure you provide a prompt using either the
-pflag or the-fflag.
- Make sure you provide a prompt using either the
This script is licensed under the MIT License. See the LICENSE file for more information.