A CLI tool for generating code using the OpenAI API
Project description
LangChain CLI - PyPI
Overview
The LangChain CLI is a powerful command-line tool that leverages the OpenAI API to generate code snippets based on user prompts. It is designed to assist developers by providing code suggestions and templates, making the coding process more efficient. 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 Sessions: Save the current state of your prompts and generated code for later use.
- Load Sessions: Load previously saved sessions to continue working seamlessly.
- Save Generated Code: Directly save generated code to specified files.
- Configuration Management: Easily configure your OpenAI API key and other settings.
Installation
Prerequisites
- Python 3.7 or higher
- OpenAI API key
Steps
-
Clone the repository:
git clone https://github.com/basith-ahmed/langchain-cli-v2.git cd langchain-cli-v2
-
Install the required packages:
pip install -r requirements.txt
-
Configure your OpenAI API key:
python cli.py configure
Usage
Generate Code
Generate code based on a prompt.
python cli.py generate-code "Create a Python function to add two numbers"
Output:
Generated Code:
def add(a, b):
return a + b
Save Generated Code to File
Generate code and save it to a file.
python cli.py generate-code "Create a Python function to subtract two numbers" --file-name subtract.py
Output:
Generated Code:
def subtract(a, b):
return a - b
Code saved to subtract.py
Save Session
Save the current session with a specific name.
python cli.py save-session --session-name my_session --prompt "Create a Python function to add two numbers"
Output:
Session my_session saved
Load Session
Load a previously saved session.
python cli.py load-session --session-name my_session
Output:
Loaded Session:
{
"prompt": "Create a Python function to add two numbers",
"generated_code": "def add(a, b):\n return a + b"
}
Configure API Key
Configure the OpenAI API key.
python cli.py configure
Output:
Enter your OpenAI API key: <your_api_key>
Command Reference
generate-code
Generate code based on a prompt.
Usage:
python cli.py generate-code "Create a Python function to add two numbers"
Options:
--file-name: Save the generated code to a specified file.
save-session
Save the current session with a specified name.
Usage:
python cli.py save-session --session-name my_session --prompt "Create a Python function to add two numbers"
load-session
Load a previously saved session.
Usage:
python cli.py load-session --session-name my_session
configure
Configure the OpenAI API key.
Usage:
python cli.py configure
Project Structure
langchain-cli-v2/
├── cli.py
├── api_client.py
├── openai_api.py
├── session_manager.py
├── code_storage.py
├── config_manager.py
├── error_handler.py
├── logger.py
├── tests/
│ ├── test_cli.py
│ ├── test_api_client.py
│ ├── test_openai_api.py
│ ├── test_session_manager.py
│ ├── test_code_storage.py
│ ├── test_config_manager.py
│ ├── test_error_handler.py
│ └── test_logger.py
├── config/
│ ├── default_config.yaml
│ └── user_config.yaml
├── docs/
│ ├── index.md
│ ├── installation.md
│ ├── usage.md
│ ├── configuration.md
│ └── api_reference.md
├── sessions/
│ └── my_session.json
├── requirements.txt
└── .gitignore
Development
Running Tests
To run the unit tests:
pytest tests/
Output:
============================= test session starts =============================
collected 8 items
tests/test_api_client.py .... [ 50%]
tests/test_code_storage.py . [ 62%]
tests/test_config_manager.py . [ 75%]
tests/test_error_handler.py . [ 87%]
tests/test_logger.py . [100%]
============================= 8 passed in 0.45s ==============================
Adding New Features or Fixes
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and add tests for them.
- Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openwiz-1.2.5.tar.gz.
File metadata
- Download URL: openwiz-1.2.5.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26426224f016dabe33ede93a00415733b7595557958cb94d95de4a60563ea33e
|
|
| MD5 |
d601fa97bb07b2af287ae0d85df74656
|
|
| BLAKE2b-256 |
9c387535dea7b883ddbfb31ae39a56f287a6227e424ea9a40770b0acc07c0bd1
|
File details
Details for the file openwiz-1.2.5-py3-none-any.whl.
File metadata
- Download URL: openwiz-1.2.5-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7d5defd854df22a8928178d78e4218d86b954e59ff5cc4ecc727beaeefe7d0a
|
|
| MD5 |
827c1ca351f1b2be2aff89ad54d6053f
|
|
| BLAKE2b-256 |
e89daec8cfceff75343d39cf4178a43241f1477089c1a31164f067f72e6434f0
|