From 363cc8d95ff8dfac5c2ff2c9e908fd075a4355f6 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Sat, 10 Feb 2024 18:30:05 -0600 Subject: [PATCH] Added docs --- README.md | 90 +++++++++++++++++- docs/cli.rst | 142 ++++++++++++++++++++++++++++ docs/description.rst | 14 +++ docs/index.rst | 6 +- docs/installation.rst | 22 +++++ src/codergpt/optimizer/optimizer.py | 2 +- 6 files changed, 271 insertions(+), 5 deletions(-) create mode 100644 docs/cli.rst create mode 100644 docs/description.rst create mode 100644 docs/installation.rst diff --git a/README.md b/README.md index 67f5edf..629f0b8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,12 @@ ## Description -CoderGPT CLI is a command line interface, a state-of-the-art code generation/modifying tool. It allows developers to interact with the CoderGPT functionalities directly from the terminal, streamlining their workflow and enhancing productivity. The underlying engine that facilitates the code enhancement and modificatoin is [langchain](https://github.com/langchain-ai/langchain). +CoderGPT CLI is a command line interface, a state-of-the-art code +generation/modifying tool. It allows developers to interact with the +CoderGPT functionalities directly from the terminal, streamlining their +workflow and enhancing code. The underlying engine that facilitates +the code enhancement and modification is `langchain +`_. ## Author @@ -87,7 +92,7 @@ code [OPTIONS] COMMAND [ARGS]... ``` #### Example - Let's consider a python file `greetings.py`: - ``` + ```python def greet(name): return f"Hello, {name}!" @@ -100,7 +105,7 @@ code [OPTIONS] COMMAND [ARGS]... $ code comment greetings.py --overwrite ``` results in .... - ``` + ```python def greet(name): """ Generates a greeting message for the given name. @@ -115,6 +120,85 @@ code [OPTIONS] COMMAND [ARGS]... user_name = "Alice" print(greet(user_name)) ``` +4. `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. + + ```shell + code optimize [--overwrite/--no-overwrite] + ``` + #### Example + - Let's consider a python file `example.py`: + ```python + # 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 + ``` + ```shell + $ code optimize example.py --overwrite + ``` + results in .... + ```python + """ + 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. + """ + ``` + ## Development The CLI is built using Python and the `click` library. Below is an example of how to define a new command: diff --git a/docs/cli.rst b/docs/cli.rst new file mode 100644 index 0000000..7861f91 --- /dev/null +++ b/docs/cli.rst @@ -0,0 +1,142 @@ +Command Line Interface (CLI) +---------------------------- + +Run the CLI using the following syntax: + +.. code-block:: shell + + 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 +~~~~~~~~ + +1. **inspect**: Inspect a package and display a file-language map. + + .. code-block:: shell + + code inspect + + **Example** + + .. code-block:: shell + + $ code inspect src/codergpt/ + Inspecting the code. + File Language + ------------------------------------------ ---------- + src/codergpt/constants.py Python + src/codergpt/__init__.py Python + src/codergpt/cli.py Python + ... + +2. **explain**: Explain a specific function or class within a package. + + .. code-block:: shell + + code explain [--function ] [--classname ] + + **Example** + + .. code-block:: shell + + $ 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... + +3. **comment**: Add comments to the code in a package. The user has the choice to overwrite the file or create a new one. + + .. code-block:: shell + + code comment [--overwrite/--no-overwrite] + + **Example** + + - Let's consider a python file `greetings.py`: + + .. code-block:: python + + def greet(name): + return f"Hello, {name}!" + + if __name__ == "__main__": + user_name = "Alice" + print(greet(user_name)) + + .. code-block:: shell + + $ code comment greetings.py --overwrite + + results in .... + + .. code-block:: python + + def greet(name): + """ + Generates a greeting message for the given name. + ... + """ + +4. **optimize**: Optimizes and adds comments to the code in a package. The user has the choice to overwrite the file or create a new one. + + .. code-block:: shell + + code optimize [--overwrite/--no-overwrite] + + **Example** + + - Let's consider a python file `example.py`: + + .. code-block:: python + + # 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-block:: shell + + $ code optimize example.py --overwrite + + results in .... + + .. code-block:: python + + """ + Optimized and Documented Code: + ... + """ + +Development +----------- + +The CLI is built using Python and the `click` library. Below is an example of how to define a new command: + +.. code-block:: python + + 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 diff --git a/docs/description.rst b/docs/description.rst new file mode 100644 index 0000000..57658dd --- /dev/null +++ b/docs/description.rst @@ -0,0 +1,14 @@ +.. _codergpt-cli: + +CoderGPT CLI +============ + +Description +----------- + +CoderGPT CLI is a command line interface, a state-of-the-art code +generation/modifying tool. It allows developers to interact with the +CoderGPT functionalities directly from the terminal, streamlining their +workflow and enhancing code. The underlying engine that facilitates +the code enhancement and modification is `langchain +`_. diff --git a/docs/index.rst b/docs/index.rst index f78101b..afafa17 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -8,8 +8,12 @@ Welcome to CoderGPT's documentation! .. toctree:: :maxdepth: 2 - :caption: Contents: + :caption: Getting Started + :name: start + description + installation + usage modules Indices and tables diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..e9999c9 --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,22 @@ +Installation +------------ + +To use the CoderGPT CLI, clone the repository and install the required dependencies. + +.. code-block:: shell + + pip install codergpt + +The most recent code and data can be installed directly from GitHub with: + +.. code-block:: shell + + pip install git+https://github.com/hrshdhgd/CoderGPT.git + +To install in development mode (using `poetry`), use the following: + +.. code-block:: shell + + $ git clone git+https://github.com/hrshdhgd/CoderGPT.git + $ cd CoderGPT + $ poetry install \ No newline at end of file diff --git a/src/codergpt/optimizer/optimizer.py b/src/codergpt/optimizer/optimizer.py index e20a9b1..6b515ef 100644 --- a/src/codergpt/optimizer/optimizer.py +++ b/src/codergpt/optimizer/optimizer.py @@ -50,7 +50,7 @@ def optimize( } ) else: - # Explain full code + # Optimize full code response = self.chain.invoke( { "input": f"Optimize, comment and add sphinx style docstrings"