Coder Social home page Coder Social logo

graykode / ai-docstring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nilsjpwerner/autodocstring

306.0 4.0 24.0 2.49 MB

Visual Studio Code extension to quickly generate docstrings for python functions using AI(NLP) technology.

Home Page: https://marketplace.visualstudio.com/items?itemName=graykode.ai-docstring

License: Other

TypeScript 38.04% HTML 1.02% Python 8.37% Starlark 0.17% Shell 0.15% Dockerfile 0.25% Jupyter Notebook 51.99%
nlp bert code-summarization docstrings vs-code-extenstion

ai-docstring's Introduction

Build Status Installs Rating

VSCode Python AI Docstring Generator

Visual Studio Code extension to quickly generate docstrings for python functions using AI(NLP) technology. This project is forked for NilsJPWerner/autoDocstring. Previously, the description of the function had to be written by the user, but the AI would see the code and summarize.

Auto Generate Docstrings

Features

  • AI Quickly generate a docstring snippet that can be tabbed through.
  • Choose between several different types of docstring formats.
  • Infers parameter types through pep484 type hints, default values, and var names.
  • Support for args, kwargs, decorators, errors, and parameter types

Docstring Formats

  • Google (default)
  • docBlockr
  • Numpy
  • Sphinx
  • PEP0257 (coming soon)

Usage

Usage is very simple. You just (1) run the container for the model inference server and (2) install extension in vscode and use.

(1) Run the container for the model inference server

  1. If you have GPU machine : docker run -it -d --gpus 0 -p 5000:5000 graykode/ai-docstring:gpu, after installing nvidia-docker.
  2. If you have only CPU : a. Run flask server with google colab and ngrok(Recommend!) or b. use docker cpu image : docker run -it -d -p 5000:5000 graykode/ai-docstring:cpu
    • At this time, it is very likely to cause OOM problem. We need more memory limit than roughly 2GB. So add --memory 2g --memory-swap parameter in linux and change memory limit in Preferences > Advanced more than 2GB(default) in macOS.

(2) Install extension in vscode and use

Cursor must be on the line directly below the definition to generate full auto-populated docstring

  • Press enter after opening docstring with triple quotes (""" or ''')
  • Keyboard shortcut: ctrl+shift+2 or cmd+shift+2 for mac
    • Can be changed in Preferences -> Keyboard Shortcuts -> extension.generateDocstring
  • Command: Generate Docstring
  • Right click menu: Generate Docstring

Extension Settings

Extension Settings are the same as the mother project except for autoDocstring.ServerEndpoint :

  • ai-docstring.ServerEndpoint: endpoint address accessible to the server.

About training and dataset

For training data, github/CodeSearchNet was used, and as an initial model, we used Code2NL(Code to Natural Language) fine-tuning tasks in microsoft/CodeBERT. For detailed instructions, refer to the paper (CodeBERT: A Pre-Trained Model for Programming and Natural Languages) and this section.

Inference Benchmark(mean of 100 trials)

Device beam_size max_source_length max_target_length Time(ms)
CPU 1 256 128 470
CPU 10 256 128 1332
CPU 1 512 128 511
CPU 10 512 128 1954
GPU 1 256 128 165
GPU 10 256 128 381
GPU 1 512 128 205
GPU 10 512 128 545
  • CPU : Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
  • GPU : Nvidia Tesla T4

License

This project is licensed under the Apache 2.0 License which is based on MIT License.

ai-docstring's People

Contributors

bastienboutonnet avatar chirieac avatar cjonesy avatar graykode avatar haaleo avatar md2perpe avatar modelmat avatar nilsjpwerner avatar s-kovacevic avatar stigjb avatar toonow avatar uebelandre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ai-docstring's Issues

[Feature Request] Add OpenAI as an alternative

One of my machines is not powerful enough for local AI, and also I don't wanna deal with docker and everything for a VSCode extension. Having the option is great, but it being the only option is really bad for usability.

OpenAIs API is relatively easy to implement, so I don't think it should be that hard.

Error: Request failed with status code 403

Error: Request failed with status code 403

Anytime I've tried to use autodocstring in VS Code, it generates a docstring with arguments, inserts it, successfully inserts the docstring the produces and error code 403.

Versions (please complete the following information):

  • autoDocstring Version: v0.1.3
  • Operating System: Mac OS 14.1 (23B74)
  • Vscode Version: 1.84.1 (Universal)

Original Code (with line to generate on):

class TableOfContents(BaseModel):
    """Super Gene's Table of Contents."""
    chapters: List[TocChapter] = []
    
    def __init__(
        self,
        html: Path = TOC_HTML_PATH,
        save: bool = True,
        verbose: bool = False) -> None:
       """${cursor}"""

Expected Result:

class TableOfContents(BaseModel):
    """Super Gene's Table of Contents."""
    chapters: List[TocChapter] = []
    
    def __init__(
        self,
        html: Path = TOC_HTML_PATH,
        save: bool = True,
        verbose: bool = False) -> None:
        """The table of contents.

        Args:
            html (Path, optional): The path to the table of contents html file. Defaults to 
                  TOC_HTML_PATH.
            save (bool, optional): Whether to save the table of contents to disk after initializing 
                  it. Defaults to True.
            verbose (bool, optional): Whether to print logging messages to the console. Defaults 
                 to False.
        """

Actual Result:

class TableOfContents(BaseModel):
    """Super Gene's Table of Contents."""
    chapters: List[TocChapter] = []
    
    def __init__(
        self,
        html: Path = TOC_HTML_PATH,
        save: bool = True,
        verbose: bool = False) -> None:
        """AI is creating summary for __init__

        Args:
            html (Path, optional): [description]. Defaults to TOC_HTML_PATH.
            save (bool, optional): [description]. Defaults to True.
            verbose (bool, optional): [description]. Defaults to False.
        """

Stack trace:
If an error was reported by autodocstring please copy the stack trace from the autoDocstring output channel.

[INFO 07:09:30.485] ai-docstring was activated
[INFO 09:38:20.492] Generating Docstring at line: 124
[INFO 09:38:20.496] Docstring generated:
        """${1:AI is creating summary for parse_dict}

        Args:
            arg (${2:dict[str, int}): ${3:[description]}
            verbose (${4:bool}, optional): ${5:[description]}. Defaults to False.

        Raises:
            TypeError: ${6:[description]}
            ValueError: ${7:[description]}
            ValueError: ${8:[description]}
            ValueError: ${9:[description]}

        Returns:
            ${10:[type]}: ${11:[description]}
        """
[INFO 09:38:20.496] Inserting at position: 124 0
[INFO 09:38:20.503] Successfully inserted docstring
[ERROR 09:38:20.510] Error: Request failed with status code 403
[INFO 11:58:35.684] Generating Docstring at line: 225
[INFO 11:58:35.688] Docstring generated:
        """${1:AI is creating summary for __init__}

        Args:
            html (${2:Path}, optional): ${3:[description]}. Defaults to TOC_HTML_PATH.
            save (${4:bool}, optional): ${5:[description]}. Defaults to True.
            verbose (${6:bool}, optional): ${7:[description]}. Defaults to False.
        """
[INFO 11:58:35.688] Inserting at position: 225 0
[INFO 11:58:35.735] Successfully inserted docstring
[ERROR 11:58:35.741] Error: Request failed with status code 403

Additional context
Add any other context about the problem here.

Unable to start the AI server via docker

Following https://github.com/graykode/ai-docstring#1-run-the-container-for-the-model-inference-server
when I run

docker run -it -d -p 5000:5000 --memory 2g --memory-swap -1 graykode/ai-docstring:cpu

I dont see any containers running via

docker ps -a

I got the following logs

docker logs -t <exited container name>

OSError: Can't load config for 'microsoft/codebert-base'. Make sure that:
'microsoft/codebert-base' is a correct model identifier listed on 'https://huggingface.co/models'
or 'microsoft/codebert-base' is the correct path to a directory containing a config.json file

How to use ai-docstring with a RTX4080 ?

Dear Authors:

I found that I can't run the docker normally when I connect the right ip and ports.The terminal returned the message that Error: Request failed with status code 500.So I checked the docker and found that it showed the following messages:

02/21/2023 10:37:37 - INFO - utils - Namespace(beam_size=10, device=device(type='cuda'), device_name='cuda', host='0.0.0.0', max_source_length=512, max_target_length=128, no_cuda=False, port=5000)
/usr/local/lib/python3.6/dist-packages/torch/cuda/init.py:125: UserWarning:
NVIDIA GeForce RTX 4080 Laptop GPU with CUDA capability sm_89 is not compatible with the current PyTorch installation.
The current PyTorch install supports CUDA capabilities sm_37 sm_50 sm_60 sm_70 sm_75.
If you want to use the NVIDIA GeForce RTX 4080 Laptop GPU GPU with PyTorch, please check the instructions at https://pytorch.org/get-started/locally/

warnings.warn(incompatible_device_warn.format(device_name, capability, " ".join(arch_list), device_name))
02/21/2023 10:37:46 - WARNING - werkzeug - * Debugger is active!
02/21/2023 10:37:46 - INFO - werkzeug - * Debugger PIN: 330-130-214

then it stopped outputting anything.

I think the reason why I can't run it is that my GPU is not suitable for the Pytorch version used by this docker image.But I am not good at setting docker.So what should I do to normally use your work?

Thank you and waitting for your answer.

Error code 500

Describe the bug
Successfully ran docker line for gpu machine using normal docker.
docker run -it -d --gpus 0 -p 5000:5000 graykode/ai-docstring
Extension activates but then encounters error code 500

Versions (please complete the following information):

  • autoDocstring Version:
  • Operating System:
  • Vscode Version:

Original Code (with line to generate on):

def gaussDeriv2D(sigma):
    # generate on this line
    # Your code to generate Gx and Gy here. use partial dervitive of gaussian equations
    Gy = sigma * 5
    Gx = sigma * 3

    return Gx, Gy

Expected Result:

"""
Docstring generated
"""

Actual Result:
"""AI is creating summary for gaussDeriv2D

Args:
    sigma ([type]): [description]

Returns:
    [type]: [description]
"""

Stack trace:

[INFO 23:26:14.797] Generating Docstring at line: 1
[INFO 23:26:14.797] Docstring generated:
    """${1:AI is creating summary for gaussDeriv2D}

    Args:
        sigma (${2:[type]}): ${3:[description]}

    Returns:
        ${4:[type]}: ${5:[description]}
    """
[INFO 23:26:14.797] Inserting at position: 1 0
[INFO 23:26:14.811] Successfully inserted docstring
[ERROR 23:26:14.837] Error: Request failed with status code 500

Additional context
Add any other context about the problem here.

Container crashes when trying to create description

Hi,

Trying to run this on Mac OS X Catalina (MBP 15" 2018)

Running Docker Desktop, tried launch the container CPU-only. It downloads/launches fine but crashes when I tried to use the extension in vscode.

The function I am trying to summarize is

def plus(a: int, b:int) -> int: return a+b

Although it crashed on other functions too

Here are the two errors I get

[INFO 13:13:23.064] Generating Docstring at line: 2
[INFO 13:13:23.067] Docstring generated:
    """${1:AI is creating summary for plus}

    Args:
        a (${2:int}): ${3:[description]}
        b (${4:int}): ${5:[description]}

    Returns:
        ${6:int}: ${7:[description]}
    """
[INFO 13:13:23.067] Inserting at position: 2 0
[INFO 13:13:23.081] Successfully inserted docstring
[ERROR 13:13:23.084] Error: connect ECONNREFUSED 127.0.0.1:5000

another time it was this:

[INFO 13:15:19.118] Generating Docstring at line: 2
[INFO 13:15:19.120] Docstring generated:
    """${1:AI is creating summary for plus}

    Args:
        a (${2:int}): ${3:[description]}
        b (${4:int}): ${5:[description]}

    Returns:
        ${6:int}: ${7:[description]}
    """
[INFO 13:15:19.120] Inserting at position: 2 0
[INFO 13:15:19.127] Successfully inserted docstring
[ERROR 13:15:32.992] Error: socket hang up

Before the crash this is what I see in docker ps

CONTAINER ID        IMAGE                   COMMAND             CREATED             STATUS              PORTS                    NAMES
30216d40636d        graykode/ai-docstring   "python3 app.py"    18 seconds ago      Up 17 seconds       0.0.0.0:5000->5000/tcp   hopeful_davinci

Immediate Crash on MacOS

I'm attempting to use this on Mac Ventura and running into a very similar issue to #1. The output is the same, but the error is not with memory, or at least Docker Desktop's default memory on my computer is 8Gb, not 2, so I would have expected that to be enough.

The error happens immediately, too, which seems odd if it were to be a memory issue.

Specifically, I am initializing the image with docker run -it -d -p 5003:5000 graykode/ai-docstring:cpu (can't download the Weights to run the ngrok notebook). I use port 5003 locally since Apple uses 5000 for AirDrop.

I get the error:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

followed by what appears to be the image hash, identifier, etc.

I have my setting in VSCode set to:

"ai-docstring.ServerEndpoint": "127.0.0.1:5003"

The image seems to run fine, but upon calling Generate Docstring, I get an Error: socket hang up.

Feature Request: Also generate [extended_summary]

Describe the request

It would be great to also receive generated text for the [extended_summary] tag.

Versions (please complete the following information):

  • autoDocstring Version: 0.1.3
  • Operating System: Windows 11 Pro 22H2 22621.1555
  • Vscode Version: 1.77.3

Docstring format being ignored in settings.json

Describe the bug
When I set the "autoDocstring.docstringFormat": "numpy" in the settings.json the file it is ignored, and google style is used instead.
When I use the normal auto docstring library it works fine.

Versions:

  • autoDocstring Version: ???
  • Operating System: Ubuntu
  • Vscode Version: 1.52.1

Error: Request failed with status code 404

Describe the bug
A clear and concise description of what the bug is.

Versions (please complete the following information):

  • autoDocstring Version: 0.1.3
  • Operating System: Windows 10
  • Vscode Version: 1.65.2

Original Code (with line to generate on):

class IndexView(generic.ListView):
    model = Category
    queryset = Category.objects.filter()
    template_name = 'landing/index.html'

Actual Result:

Error: Request failed with status code 404

Additional context
Upon using ai-docstring on my Django project I was getting the error Error: connect ECONNREFUSED 127.0.0.1:5000. I tried changing ai-docstring: sever endpoint to 127.0.0.1:8000.
Now I get the error 'Error: Request failed with status code 404'. Also, it seems like after using the extension, it sends a post request to the 'summery' URL which cannot be found on my running Django localserver:
'POST /summary HTTP/1.1" 404 2712'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.