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.5.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.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openwiz-1.3.5.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.5.tar.gz
Algorithm Hash digest
SHA256 413c7fd13240d9a71f7c99696623cc3ee1e781dc530a0a6904fd5c33bd9d6f0e
MD5 ee9fa3ed572cc92a286fb2525eaa3cf0
BLAKE2b-256 8ba7630b71e844a3535a3b696486d4e1e49149fdccee0ea35b0180bec8f5dc0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: openwiz-1.3.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f320e1fd0ebcb1dddf9142411651555cbfcc85a0608b12e69d963016f9469bdf
MD5 c714fe85420042609fac552c130e1d3a
BLAKE2b-256 34dbad1fa0216978bb5878836baa50bcbe2f99ca1e352dd43953d56ff132f377

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