Skip to main content

Command GPT

A simple command-line utility to interact with OpenAI's API and retrieve shell suggestions. By default, predefined system and user messages are used to facilitate the interaction. However, flags are available to allow customization of these messages per request.

Prerequisites

  1. Python 3
  2. OpenAI API Key

Install

pip install commandgpt

Usage

On the first run, Command GPT will create a configuration file named .openai_config in your home directory and prompt you for details. This file will store the OpenAI API key, model version, user and system messages to facilitate future interactions without the need to repeatedly input those details.

└─$ gpt -h                                                        
usage: gpt [-h] [-s SYSTEM] [-u USER] [-d] [-c] [-v] [query]

Interact with OpenAI ChatGPT.

positional arguments:
  query                 your question or query

options:
  -h, --help            show this help message and exit
  -s SYSTEM, --system SYSTEM
                        system message for AI
  -u USER, --user USER  prefix for user message
  -d, --debug           enable debug mode
  -c, --config          reconfigure settings
  -v, --version         show the version number and exit

Example System and User messages

System:

You are a super star linux system admin.

User:

Provide very brief answers without any explanation. Write one-liner commands as answers.

Example usage

$ gpt "Your query here"

However, if you wish to customize the system or user messages:

$ gpt "Your query here" --system "Your custom system message" --user "Your custom user prefix"
$ gpt "How do I check disk space?"
df -h
$ gpt "How can I see all running processes?"
ps aux
$ gpt "How do I find my machine's IP address?"
ip a

Output Safety Warning

The output from Command GPT is not escaped or quoted by default. This means that special characters or command structures in the output can have direct consequences if executed in a shell or scripting environment.

Using the raw output in scripts or as part of piped commands can be hazardous. I strongly advise against directly integrating the output of Command GPT into another command, script, or pipeline without meticulously reviewing and understanding its implications.

Before utilizing any output, please ensure you're fully aware of its content and potential side effects.

A Word of Caution!

While GPT aims to provide accurate and efficient command suggestions, it's essential to understand the commands and not take them at face value. As with any AI system, the output it produces may not always reflect the most accurate or optimal solution for a given task.

Illustrative Example: Counting Lines in Text Files

Imagine you want to count all the lines in .txt files within a directory, recursively. You might get two suggestions:

  1. find /path/to/directory -type f -name "*.txt" -exec wc -l {} + | awk '{sum += $1} END {print sum}'
  2. find /path/to/directory -name "*.txt" -exec cat {} + | wc -l

At first glance, both might seem to do the job. However, upon closer inspection, the first command might return a count that's double the actual number of lines. Why? Because wc -l produces an output line for each file and a cumulative count when used with multiple files. The awk part then sums all these numbers, leading to an inflated total.

The lesson here? Always review and understand the commands you get. Even if a command looks technically correct, it may not deliver the expected result in every context.

Command GPT is a tool, and like any tool, its effectiveness depends on the skill and awareness of the user.

TODO

  • Think of a better way to store API key (keyring module?).
  • Add more openai models including images.

License

MIT

Metadata

Release files for commandgpt 0.1.1

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

Source distribution (sdist)

Source distribution for commandgpt 0.1.1
File Size Uploaded
commandgpt-0.1.1.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for commandgpt 0.1.1
File Interpreter ABI Platform
commandgpt-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / commandgpt-0.1.1.tar.gz

Download URL commandgpt-0.1.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
93912d48a2e3f2b8f344c39b9b05b3a0b79f3382c62a0098f22cb18f8d566d7f
BLAKE2b-256 checksum
How to use checksums
c1d4650abe7739866d0aedb4c50f24affdfcac8ea0ca8fa7afd9f071f350b3a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / commandgpt-0.1.1-py3-none-any.whl

Download URL commandgpt-0.1.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83148931fcaa102cb2fbead6a0b9f3849261412407b79abce9bb65e2a31557eb
BLAKE2b-256 checksum
How to use checksums
71c53c5e1694d10e0fd07770ad56beddb138a0957f6532cb71d129f7035635bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.1.1 This release

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