# gptcmd: Command-Line Interface for OpenAI GPT-3

![](featured-image.webp#centeri_nor)

`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.

## Usage

```bash
gptcmd.py <mode> [options]
```

### Modes

- `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`.

### Options

- `-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.

## Requirements

- Python 3.x
- `openai` Python library
- OpenAI API key

## Installation

1. Install the `openai` Python library:

```bash
pip install openai
```

2. Set your OpenAI API key as an environment variable:

```bash
export OPENAI_API_KEY=your_api_key
```

## Examples

1. Chunk mode:

```bash
gptcmd.py c -i input.txt -o output.txt -p "Rewrite this paragraph in a more engaging way:" -n 100
```

2. Query mode:

```bash
gptcmd.py q -p "What is the capital of France?"
```

3. Run mode:

```bash
gptcmd.py r -q "Create a new folder named 'example_folder'"
```

In the examples above, replace `your_api_key` with your actual API key.

## Download

You can download gptcmd [here](gptcmd.zip)

