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.
- 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.
- Python 3.7 or later
- OpenAI API key
-
Clone the Repository:
git clone https://github.com/basith-ahmed/openwiz.git cd openwiz
-
Virtual Environment Setup:
python -m venv venv .\venv\Scripts\activate pip install -r requirements.txt
-
API Key Configuration:
python src\cli.py configure
python src\cli.py configure
Output:
Enter your OpenAI API key: <your_api_key>
python src\cli.py generate "Create a Python function to add two numbers"
Sample Output:
Generated Code:
def add(a, b):
return a + b
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
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
.
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.
Install the package from PyPI to integrate with existing projects.
pip install openwiz
Configure the OpenAI API key and utilize the CLI functionalities as demonstrated in the previous section.
owc configure
owc generate "Create a Python function to add two numbers"
owc generate "Create a Python function to subtract two numbers" --file-name subtract.py
owc save --session-name my_session --prompt "Create a Python function to add two numbers"
owc load --session-name my_session
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. |
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.
Contribute to the project by following these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Implement changes and add corresponding tests.
- Commit the changes (
git commit -am 'Add new feature'
). - Push the changes to the branch (
git push origin feature-branch
). - Create a new Pull Request for review and integration.
We welcome contributions! Please see the CONTRIBUTING.md file for more details.
This project is licensed under the MIT License. See the LICENSE file for details.