LLM-based Python Docstring Generator: Enhancing Python Documentation with AI
The LLM-based Python Docstring Generator is a cutting-edge Visual Studio Code extension designed to streamline the documentation process for Python developers. By harnessing the power of AI and Natural Language Processing (NLP), this tool automatically generates comprehensive docstrings for Python functions, saving you time and ensuring consistency in your code documentation.
Key Features:
- AI-Powered Docstring Generation: Utilizes a quantized version of Mistral-AI's 7B model to produce detailed docstrings.
- Multiple Docstring Formats: Supports Google (default), docBlockr, Numpy, and Sphinx formats, catering to different documentation styles.
- Customizable Templates: Attempts to include variable types and descriptions according to the chosen template, enhancing the clarity of your documentation.
Important Note:
To use this extension, you must run an LLM instance. Detailed instructions on setting up the backend are provided in the Usage section below.
Usage:
Backend Setup:
(1) ngrok & Google Colab Solution:
- Create accounts on ngrok and Google Colab.
- Open the server notebook on Google Colab.
- Replace
with your ngrok authtoken in the second cell and uncomment the line. - Run all cells.
- Copy the ngrok address (without https) into the extension settings under
llmdocstring.ServerEndpoint.
(2) Local Setup:
- Create and activate a new Python environment (version 3.9 recommended).
- In the
serverdirectory, install dependencies usingpip install -r requirements.txt. - Install
llama-cpp-pythonaccording to your hardware specifications. - Run
python llmserver.py. - Set
127.0.0.1:5000as thellmdocstring.ServerEndpointin the extension settings.
Using the Extension in VSCode:
- Place your cursor directly below the function definition.
- Open the docstring with triple quotes (
"""or'''). - Press Enter to trigger auto-population of the docstring.
- Use the keyboard shortcut
Ctrl+Shift+2(Windows) orCmd+Shift+2(Mac), which can be customized in Preferences -> Keyboard Shortcuts ->extension.generateDocstring. - Alternatively, use the command "Generate Docstring" or right-click and select "Generate Docstring" from the context menu.
Demo:
Experience the tool in action with this real-time demo using Google Colab T4 runtime as the backend: Demo Video.
Conclusion:
The LLM-based Python Docstring Generator revolutionizes the way Python developers document their code. By integrating AI technology into your development workflow, this VSCode extension ensures that your functions are thoroughly and accurately documented, enhancing code readability and maintainability.
