Skip to main content

A CLI tool for generating code using the OpenAI API

Project description

OpenWiz CLI - PyPI

Overview

The OpenWiz CLI is a powerful command-line tool that utilizes the OpenAI API to generate code snippets based on user prompts. It is designed to assist developers by providing code suggestions and templates directly into their development environment, thereby enhancing coding efficiency. The CLI also offers functionalities to save and load sessions, manage configurations, and handle generated code effectively.

Features

  • Generate Code: Create code snippets based on textual prompts using the OpenAI API.
  • Save Generated Code: Directly save generated code to specified files.
  • Save and Load Sessions: Save the current state of your prompts and generated code for later use and seamlessly continue working with previously saved sessions.
  • Configuration Management: Easily configure your OpenAI API key and other settings.

Installation Guide

Prerequisites

  • Python 3.7 or later
  • OpenAI API key

Developer Setup

  1. Clone the Repository:

    git clone https://github.com/basith-ahmed/openwiz.git
    cd openwiz
    
  2. Virtual Environment Setup:

    python -m venv venv
    .\venv\Scripts\activate
    pip install -r requirements.txt
    
  3. API Key Configuration:

    python src\cli.py configure
    

Usage Instructions

1. Configuration

python src\cli.py configure

Output:

Enter your OpenAI API key: <your_api_key>

2. Code Generation

python src\cli.py generate "Create a Python function to add two numbers"

Sample Output:

Generated Code:
def add(a, b):
    return a + b

3. Saving Generated Code

python src\cli.py generate "Create a Python function to subtract two numbers" --file-name subtract.py

Sample Output:

Generated Code:
def subtract(a, b):
    return a - b

> Code saved to subtract.py

4. Session Management

Save the current session with a specific name for later retrieval.

python src\cli.py save --session-name my_session --prompt "Create a Python function to add two numbers"

Sample Output:

Generated Code:
def add(a, b):
    return a + b

> Session my_session saved

Explanation: This command saves the current session with the provided prompt under the name my_session.

5. Loading Sessions

Load a previously saved session to resume work from a specific state.

python src\cli.py load --session-name my_session

Sample Output:

Loaded Session:
{
    "prompt": "Create a Python function to add two numbers",
    "generated_code": "def add(a, b):\n    return a + b"
}

Explanation: This command loads the session named my_session, allowing access to the associated prompt and generated code.

Installation

Install the package from PyPI to integrate with existing projects.

pip install openwiz

Configuration and Usage

Configure the OpenAI API key and utilize the CLI functionalities as demonstrated in the previous section.

1. Configuration

owc configure

2. Code Generation

owc generate "Create a Python function to add two numbers"

3. Saving Generated Code

owc generate "Create a Python function to subtract two numbers" --file-name subtract.py

4. Session Management

owc save --session-name my_session --prompt "Create a Python function to add two numbers"

5. Loading Sessions

owc load --session-name my_session

Command Reference

Command Description Options
generate Generate code based on a prompt. --file-name: Save the generated code to a specified file.
save Save the current session with a specified name. --session-name: Save the generated code as a session to view later.
load Load a previously saved session. --f: Load and view all the saved sessions.
--d: Delete a specific session.
--session-name: Load a specific session from the saved sessions.
configure Configure the OpenAI API key.

Development Guidelines

Running Tests

Ensure code integrity by running unit tests.

pytest tests/

Explanation: This command executes the unit tests located in the tests directory to validate the functionality of the codebase.

Contribution Workflow

Contribute to the project by following these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Implement changes and add corresponding tests.
  4. Commit the changes (git commit -am 'Add new feature').
  5. Push the changes to the branch (git push origin feature-branch).
  6. Create a new Pull Request for review and integration.

Contributing

We welcome contributions! Please see the CONTRIBUTING.md file for more details.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

openwiz-1.3.6.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

openwiz-1.3.6-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file openwiz-1.3.6.tar.gz.

File metadata

  • Download URL: openwiz-1.3.6.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.1

File hashes

Hashes for openwiz-1.3.6.tar.gz
Algorithm Hash digest
SHA256 9955b09a07c4775322bc1fc304bbdbb3a145795e29ea23e1401532f1ed4524a9
MD5 5e57815a9cb3310188c49b5d375081fe
BLAKE2b-256 ad075aac44cece497768ff5fe369b7a807c9d982340eb65e0023cf5dc678a84e

See more details on using hashes here.

File details

Details for the file openwiz-1.3.6-py3-none-any.whl.

File metadata

  • Download URL: openwiz-1.3.6-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.1

File hashes

Hashes for openwiz-1.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8a5a19c28ed956611f75293ae9e95b262e942a69cad74c7a68fd9f0ce49d2329
MD5 48b253126bb043d83e3de15838f17654
BLAKE2b-256 d04c82531d8d0ac2c1dd1d078b903973453f537feeedcb0965d43ef2dd32361e

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