CoderGPT
Project description
CoderGPT
Description
CoderGPT is a command line interface for generating/modifying code. It allows developers to enhance code by commenting, optimizing and adding tests to their project using the power of LLM. This project is powered by langchain.
Installation
To use the CoderGPT CLI, clone the repository and install the required dependencies.
pip install codergpt
Usage
Run the CLI using the following syntax:
code [OPTIONS] COMMAND [ARGS]...
Options
-v, --verbose INTEGER
: Set verbosity level (0, 1, or 2).-q, --quiet
: Enable quiet mode.--version
: Display version information.
Commands
-
inspect
: Inspect a package and display a file-language map.code inspect <path>
Example
$ code inspect code inspect src/codergpt/ Inspecting the code. File Language ------------------------------------------ ---------- src/codergpt/constants.py Python src/codergpt/__init__.py Python src/codergpt/cli.py Python src/codergpt/extensions.yaml YAML src/codergpt/main.py Python src/codergpt/optimizer/__init__.py Python src/codergpt/utils/expression_evaluator.py Python src/codergpt/utils/__init__.py Python src/codergpt/commenter/commenter.py Python src/codergpt/commenter/__init__.py Python src/codergpt/explainer/explainer.py Python src/codergpt/explainer/__init__.py Python src/codergpt/test_writer/__init__.py Python
-
explain
: Explain a specific function or class within a package.code explain <path> [--function <function_name>] [--classname <class_name>]
Example
$ code explain src/codergpt/explainer/explainer.py --function explain Explanation for the code: This code defines a method called `explain` that takes in three parameters: `code`, `function`, and `classname`. The `code` parameter is a string that represents the code file to be explained. The `function` parameter is an optional string that represents the name of a specific function within the code file that needs to be explained. The `classname` parameter is also an optional string that represents the name of a specific class within the code file that needs to be explained. The method first checks if the `function` parameter is provided. If it is, the method invokes a `chain` by passing a dictionary with an "input" key and a formatted string containing the code. The response from the `chain.invoke` call is then printed in a pretty format, including the name of the function being explained. If the `function` parameter is not provided but the `classname` parameter is, the same process is followed, but with the class name instead. If both `function` and `classname` parameters are not provided, the method assumes that the full code needs to be explained. It again invokes the `chain` with the code as input and prints the response in a pretty format, indicating that it is explaining the entire code.
-
comment
: Add comments to the code in a package. The user has the choice to overwrite the file or create a new one.code comment <path> [--overwrite/--no-overwrite]
Example
- Let's consider a python file
greetings.py
:
def greet(name): return f"Hello, {name}!" if __name__ == "__main__": user_name = "Alice" print(greet(user_name))
$ code comment greetings.py --overwrite
results in ....
def greet(name): """ Generates a greeting message for the given name. :param name: (str) The name of the person to greet. :return: (str) The greeting message. """ return f"Hello, {name}!" if __name__ == "__main__": user_name = "Alice" print(greet(user_name))
- Let's consider a python file
-
optimize
: Optimizes and adds commets to the code in a package. The user has the choice to overwrite the file or create a new one.code optimize <path> [--overwrite/--no-overwrite]
Example
- Let's consider a python file
example.py
:
# example.py def calculate_sum(numbers): result = 0 for number in numbers: result += number return result class MathOperations: def multiply(self, a, b): answer = 0 for i in range(b): answer += a return answer
$ code optimize example.py --overwrite
results in ....
""" Optimized and Documented Code: """ from typing import List def calculate_sum(numbers: List[int]) -> int: """ Calculates the sum of a list of numbers. Parameters: numbers (List[int]): A list of integers. Returns: int: The sum of the numbers. """ result = sum(numbers) return result class MathOperations: def multiply(self, a: int, b: int) -> int: """ Multiplies two numbers. Parameters: a (int): The first number. b (int): The second number. Returns: int: The result of multiplying a and b. """ answer = a * b return answer """ Optimization: 1. In the 'calculate_sum' function, we can use the built-in 'sum' function to calculate the sum of the numbers in the list. This is more efficient than manually iterating over the list and adding each number to the result. 2. In the 'multiply' method of the 'MathOperations' class, we can directly multiply the two numbers using the '*' operator. This eliminates the need for a loop and improves performance. By using these optimizations, we improve the efficiency and readability of the code. """
- Let's consider a python file
Development
The CLI is built using Python and the click
library. Below is an example of how to define a new command:
import click
from codergpt import CoderGPT
coder = CoderGPT()
@click.command()
@click.argument('path', type=click.Path(exists=True))
def new_command(path):
# Command logic here
pass
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Acknowledgements
This cookiecutter project was developed from the monarch-project-template template and will be kept up-to-date using cruft.
For more information on CoderGPT CLI, please visit the official documentation.
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
File details
Details for the file codergpt-0.1.2.tar.gz
.
File metadata
- Download URL: codergpt-0.1.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74c9819a05954f77f2b5f1ddb6a43323edad3b1dbddc6691a4946e55faec3e50 |
|
MD5 | 63278d08e6df253dedf824a4c8bd411d |
|
BLAKE2b-256 | c3ce901e4bffcbff8eb0a53006f97563e000c7ae5de0e89bb5729f37b4b4a251 |
Provenance
File details
Details for the file codergpt-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: codergpt-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f19de0ca5e6572db055e456d95ce89ace3eb6c309c7d6c6205094a71a1703d2 |
|
MD5 | 2961f7302b4ec140cb4681d8ec2ebbc5 |
|
BLAKE2b-256 | 1be6ca97380ef26f6c2af4541579edd63a697289e40cd9cdde0b0a7e2b02d78d |