Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

ChatGPT CLI

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.

Installation

  1. Prerequisites:

    • You need to have curl and jq installed on your system.
    • An OpenAI API key is required. If you don't have one, you can get it from the OpenAI API website.
  2. 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
  3. 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"
  4. Ensure the Context Directory Exists: The script will create a contexts directory in the same folder where it is executed. If it's missing, it will be created automatically.


Usage

Command-Line Flags

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.

Example Usage

1. Start a New Conversation (with a Prompt)

./chatgpt-cli.sh -p "What is quantum computing?" -n

This will create a new context based on the provided prompt and start a new conversation.

2. Start a New Conversation (with a File)

./chatgpt-cli.sh -f "./prompt.txt" -n

This reads the prompt from the specified file (prompt.txt) and starts a new context.

3. Continue a Historic Conversation

./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.

4. Start a New Conversation with a Custom Context File Name

./chatgpt-cli.sh -f "./prompt.txt" -n

If 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).


Key Features

  1. 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).
  2. Prompt from Command Line (-p):

    • You can pass the prompt directly as a command-line argument.
  3. Prompt from File (-f):

    • Instead of typing the prompt, you can pass a file containing the prompt text.
  4. Continue Historic Context (-c):

    • Resume a previous conversation by providing the path to an existing context file.
  5. 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.
  6. Easy Integration:

    • Designed to be simple and flexible, you can integrate this script into your own projects or use it directly from the terminal.

Troubleshooting

  • 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 -p flag or the -f flag.

License

This script is licensed under the MIT License. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages