Skip to main content

Python CLI app for generating shell commands with OpenAI's GPT-3.5-turbo model

Project description

README

GShellX 💻

A Python-based CLI app powered by OpenAI's GPT-3.5-turbo model to generate responses to user prompts, with a specific focus on generating shell commands and scripts. It is interactive and supports single command execution, pre-set prompts, and maintaining a history of prompts and responses.

Features 🚀

  • Generate Command Line Commands: Generate shell commands with a description in free language of what the command should do.
  • Execute Generated Commands: Allows immediate execution of the generated command.
  • Interactive Mode: Allows entering prompts and commands on the fly.
  • History: Keeps a history of the prompts and responses for future reference.
  • Command Editing: Edit the generated command, providing greater flexibility and control over the command execution.
  • Rich Text Output: Enhanced console output experience that highlights code blocks in the responses.

Installation Instructions 📥

Prerequisites

  • Python 3.6+
  • OpenAI API key

Steps

  1. Clone this repository: git clone <repo-url>
  2. Navigate into the project directory: cd <project-directory>
  3. Create a virtual environment: python3 -m venv env
  4. Activate the virtual environment: source env/bin/activate (for Linux/Mac) or .\env\Scripts\activate (for Windows)
  5. Install required packages: pip install -r requirements.txt
  6. Set up the OpenAI key as an environment variable: export OPENAI_KEY=your_openai_key

Code Structure 📂

  • config.py: Contains the configuration for the OpenAI API like the API key and headers.
  • openai_api.py: Contains the logic for making requests to the OpenAI API.
  • prompts.py: Contains the prompts used for generating shell commands.
  • shell_utils.py: Contains utility functions for loading and saving history, printing history, and executing shell commands.
  • main.py: The main entry point of the application. It uses click to parse command-line arguments and handles the flow of the application.

Configuration 🔧

The tool requires an OpenAI key to function, which should be set as an environment variable OPENAI_KEY. Please refer to the OpenAI API documentation to obtain your API key.

Examples 📖

  1. With a prompt (-p / --prompt):

    python main.py --prompt "simple Python HTTP server with Flask."

    from flask import Flask
    
    # Create the Flask application
    app = Flask(__name__)
    
    # Define the route and handler for the root URL
    @app.route('/')
    def hello():
       return 'Hello, World!'
    
    # Start the Flask application
    if __name__ == '__main__':
       app.run()
    
  2. With a command (-c / --cmd):

    python main.py --cmd "find all files larger than 3 megabytes in the current directory and its subdirectories"

    find . -type f -size +3M
    
  3. Interactive Mode (-i / --interactive):

      python3 main.py -i
    
    Enter a prompt: command: display the top 10 processes sorted by memory usage
    
    ⠸ Processing...
    
    The command is: top -o mem -l 1 -n 10 -stats pid,command,mem -l 1 | awk '$3 > 1 {print $0}'
    
    Do you want to execute this command? (y/n) or edit (e): y
    
    Output:
    10 PID    COMMAND          MEM
    11 54499* pycharm          4004M
    12 65519* ScreenX          2760M
    13 75199* Sublime Text     1973M
    14 86418* Finder           1815M
    15 454*   WindowServer     1461M
    16 3435*  Raycast          861M
    17 33109* Brave Browser    842M
    18 25102* Brave Browser    658M
    19 77155* Brave Browser    389M
    20 23415* Brave Browser    335M
    
    Enter a prompt:
      
    

Security Considerations ⚠️

The app has the potential to execute shell commands, which comes with inherent security risks. Please review all generated commands carefully before choosing to execute them, and avoid running commands that you don't fully understand.

Contributing 🤝

If you'd like to contribute to the development of this tool, please feel free to fork the repository, make your changes, and create a pull request.

Future Work 💡

Future updates can potentially include additional interactive features, improved command generation, integration with other language models or APIs, and more.

Disclaimer ⚠️

This app is developed for demonstration purposes and is not officially associated with or endorsed by OpenAI.

License 📜

The project is released under MIT License.

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

gshellx-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

gshellx-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file gshellx-0.1.0.tar.gz.

File metadata

  • Download URL: gshellx-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/21.6.0

File hashes

Hashes for gshellx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 72111936b0d60925ca347538bf2c7ee9fe8ba1f6323d926b219e91b0d2ca96b1
MD5 b0dd45de81cdfd6c708c6d6033ab31b6
BLAKE2b-256 5e4284070906738dd65d320d679d8aa57cc94141e9cfb75a9be84335e7b50a15

See more details on using hashes here.

File details

Details for the file gshellx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gshellx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.11.3 Darwin/21.6.0

File hashes

Hashes for gshellx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20ec1de97c7496b0fa63bbf2890a3a62f931db084d1810fbf3d1b9a537b69ea4
MD5 9df58a523268a7818b42d450834eef09
BLAKE2b-256 9cb1a037a50dc10f6a019d0b7a5eef1c836fc85b887989e8266f18f58e9ec950

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