Code Monkey home page Code Monkey logo

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

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

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.