Skip to main content

CLI App allows to query OpenAI GPT-3 models using API.

Project description

Shell GPT

A command-line interface (CLI) productivity tool powered by OpenAI's Davinci model, will help you accomplish your tasks faster and more efficiently.

Description

text-davinci-003 is a powerful language model developed by OpenAI that can generate human-like text. It can be used by us, coders, to generate code snippets, comments, documentation and more, helping us increase our productivity and efficiency while coding.

Forget about cheat sheets and notes, with this tool you can get accurate answers right in your terminal, and you'll probably find yourself reducing your daily Google searches, saving you valuable time and effort.

Installation

pip install shell-gpt --user

On first start you would need to generate and provide your API key, get one here.

Use cases

Simple queries

We can use it pretty much as normal search engine, asking about anything, for example:

sgpt "nginx default config file location"
# -> The default Nginx config location is /etc/nginx/nginx.conf
sgpt "docker show all local images"
# -> You can view all locally available Docker images by running: `docker images`
sgpt "mass of sun"
# -> = 1.99 × 10^30 kg

Shell queries

Usually we are forgetting commands like chmod 444 and we want quickly find the answer in google, clicking pages, scrolling, copy&pasting, usually takes some time, but now we "google" and execute it right in the terminal using --shell flag sgpt will provide only shell commands:

# Here we are using special flag --shell, which will output only shell commands.
sgpt --shell "make all files in current directory read only"
# -> chmod 444 *

Since we are receiving valid shell command, we can execute it using eval $(sgpt --shell "make all files in current directory read only") but this is not very convenient, instead we can use --execute (or shortcut -se for --shell --execute) parameter:

sgpt --shell --execute "make all files in current directory read only"
# -> chmod 444 *
# -> Execute shell command? [y/N]: y
# ...

At this point it is already can solve half of most frequent Google searches, but how far we can push the limits of text-davinci-003 model? Let's try some docker containers:

sgpt -se "start nginx using docker, forward 443 and 80 port, mount current folder with index.html"
# -> docker run -d -p 443:443 -p 80:80 -v $(pwd):/usr/share/nginx/html nginx
# -> Execute shell command? [y/N]: y
# ...

Also, we can provide some parameters name in our prompt, for example, I want to pass input and output file names to ffmpeg:

sgpt -se "slow down video twice using ffmpeg, input video name \"input.mp4\" output video name \"output.mp4\""
# -> ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" output.mp4
# -> Execute shell command? [y/N]: y
# ...

And remember we are in shell, this means we can use outputs of any commands in our prompt, this brings it to another level, here is simple examples with ffmpeg and list of videos in current folder:

ls
# -> 1.mp4 2.mp4 3.mp4
sgpt -se "using ffmpeg combine multiple videos into one without audio. Video file names $(ls)"
# -> ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -filter_complex "[0:v] [1:v] [2:v] concat=n=3:v=1 [v]" -map "[v]" out.mp4
# -> Execute shell command? [y/N]: y
# ...

Since GPT-3 models can also do summarization and analyzing of input text, we can ask text-davinci-003 to find error in logs and provide some details:

sgpt "check these logs, find errors, and explain what the error is about: ${docker logs -n 20 container_name}"
# ...

Code queries

With --code parameters we can query only code as output, for example:

sgpt --code "Solve classic fizz buzz problem using Python"
for i in range(1, 101):
    if i % 3 == 0 and i % 5 == 0:
        print("FizzBuzz")
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)

Since it is valid python code without any other text, we can redirect the output to file:

sgpt --code "solve classic fizz buzz problem using Python" > fizz_buzz.py
python fizz_buzz.py
# 1
# 2
# Fizz
# 4
# Buzz
# Fizz
# ...

This is, just some examples of what we can do using GPT-3 models, I'm sure you will find it useful for your specific use cases.

Full list of arguments

--model                             TEXT     OpenAI model name. [default: text-davinci-003]
--max-tokens                        INTEGER  Strict length of output (words). [default: 2048]
--shell       -s                             Provide shell command as output.
--execute     -e                             Used with --shell, will execute command.
--code            --no-code                  Provide code as output. [default: no-code]
--animation       --no-animation             Typewriter animation. [default: animation]
--spinner         --no-spinner               Show loading spinner during API request. [default: spinner]
--help                                       Show this message and exit.

Docker

Use the provided Dockerfile to build a container:

docker build -t sgpt .

You may use a named volume (therefore sgpt will ask your API key only once) to run the container:

docker run --rm -ti -v gpt-config:/home/app/.config/shell-gpt sgpt "what are the colors of a rainbow"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shell_gpt-0.4.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shell_gpt-0.4.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file shell_gpt-0.4.1.tar.gz.

File metadata

  • Download URL: shell_gpt-0.4.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for shell_gpt-0.4.1.tar.gz
Algorithm Hash digest
SHA256 06a60b911474b22be2b03efd0b08691cc51f9acb5f69022666c7e060275f9ec3
MD5 fead7d81fa759f250ef75e536ef2cbaa
BLAKE2b-256 566da065018e394dab9bbbb28f87ae0c9dee13ae82ebb64e3fd585b4f849e783

See more details on using hashes here.

File details

Details for the file shell_gpt-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: shell_gpt-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for shell_gpt-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80983320ca1af63d0ca5931011cc452739d91a0000bf86efc718af43fc7cc919
MD5 5b2eba93dcbd6e7c88dd86e935a5043c
BLAKE2b-256 2511b15ac54884d52c12cb01a7889fc84a39dd4cc7c9320d599e440991643afd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page