gptcmd: Command-Line Interface for OpenAI GPT-3

/projects/gptcmd/featured-image.webp

gptcmd is a command-line tool for interacting with OpenAI’s GPT-3 language model. It offers three modes of operation:

  1. Chunk mode: Splits a text file into smaller chunks, prepends a prompt to each chunk, sends the chunk to GPT-3, and concatenates the responses into a single output file.
  2. Query mode: Sends a text query to GPT-3 and prints the response.
  3. Run mode: Sends a text query to GPT-3 with a prompt to generate executable shell code, prompts the user to execute the code, and executes the code as shell commands.
1
gptcmd.py <mode> [options]
  • c, chunk: Chunk mode. Required options: --input-file, --output-file, --prompt, --max-words-per-chunk.
  • q, query: Query mode. Required options: --query.
  • r, run: Run mode. Required options: --query.
  • -i, --input-file <filename>: Input text file for chunk mode (UTF-8 encoded).
  • -o, --output-file <filename>: Output text file for chunk mode (UTF-8 encoded).
  • -p, --prompt <prompt>: Prompt for GPT-3.
  • -n, --max-words-per-chunk <number>: Maximum number of words per chunk for chunk mode.
  • -q, --query <query>: Text query for query and run modes.
  • -h, --help: Display help message and exit.
  • Python 3.x
  • openai Python library
  • OpenAI API key
  1. Install the openai Python library:
1
pip install openai
  1. Set your OpenAI API key as an environment variable:
1
export OPENAI_API_KEY=your_api_key
  1. Chunk mode:
1
gptcmd.py c -i input.txt -o output.txt -p "Rewrite this paragraph in a more engaging way:" -n 100
  1. Query mode:
1
gptcmd.py q -p "What is the capital of France?"
  1. Run mode:
1
gptcmd.py r -q "Create a new folder named 'example_folder'"

In the examples above, replace your_api_key with your actual API key.

You can download gptcmd here