Skip to content

oliversen/chatgpt-docstrings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChatGPT: Docstring Generator

Visual Studio Marketplace Version GitHub

Automatically generate Python docstrings using ChatGPT.

Demo

Notice!

  • To use the extension you need OpenAI API key. The balance of your OpenAI profile must be positive.
  • This is a pre-release version of the extension. In case of issues, please keep feedback on github.

Table of Contents


Installation

Install it from Visual Studio Marketplace or download and install .vsix file from Releases.


Requirements

  • VSCode 1.75.0 or greater
  • Python 3.8 or greater

Usage

Code Completion

Type """ and select Generate Docstring (ChatGPT) from the completion items.

Code Completion

Context Menu

Right click in the Text Editor area and select Generate Docstring (ChatGPT).

Context Menu

Command Palette

Open the Command Palette (F1), type docstring and select Generate Docstring (ChatGPT).

Command Palette

Keyboard Shortcut

Use the following keyboard shortcut:

  • Windows/Linux: Ctrl+Alt+D
  • Mac: Cmd+Opt+D

Keyboard Shortcut

You can change the default keyboard shortcut by Keyboard Shortcuts editor (File > Preferences > Keyboard Shortcuts).


OpenAI API key

To use the extension, you will need an OpenAI API key.

Get API key

To obtain one, follow these steps:

  1. Go to OpenAI's website. Log in or sign up there.
  2. Click on the Create new secret key button.
  3. Copy the key.

Set API key

When you first generate a docstring, a pop-up window will appear requesting you to enter your API key.

Change API key

You can change the API key using the Set OpenAI API key command in the Command Palette (F1).


Settings

  • chatgpt-docstrings.interpreter: When set to a path to python executable, extension will use that to launch the server and any subprocess.

    • Default value: []
  • chatgpt-docstrings.openaiModel: Which OpenAI model to use. GPT-4, GPT-4 Turbo, and GPT-4o are available in the OpenAI API to paying customers.

    • Default value: "gpt-4o-mini"
    • Available options:
      • "gpt-4o-mini"
      • "gpt-4o"
      • "gpt-4-turbo"
      • "gpt-4"
      • "gpt-3.5-turbo"
  • chatgpt-docstrings.docstringFormat: Which docstring format to use.

    • Default value: "google"
    • Available options:
      • "google"
      • "numpy"
      • "sphinx"
  • chatgpt-docstrings.onNewLine: Start docstring on new line.

    • Default value: false
    • Available options:
      • true
      • false

    Option ignored for one-line docstring

  • chatgpt-docstrings.promptPattern: ChatGPT prompt to generate docstring.

    • Default value: "Create docstring in {docstring_format} format for python function below:\n{function}"

    The expression {docstring_format} used in the prompt will be replaced with the value of the parameter chatgpt-docstrings.docstringFormat, {function} — with the source code of the function for which the docstring will be generated.

  • chatgpt-docstrings.responseTimeout: ChatGPT response timeout in seconds.

    • Default value: 15
  • chatgpt-docstrings.showProgressNotification: Show progress notification of docstring generation.

    • Default value: true
    • Available options:
      • true
      • false

Telemetry

This extension collects anonymous information related to the usage of the extension, such as well as performance and error data. You can disable telemetry as described here.


Change Log

See Change Log here


Feedback

Submit the issues if you find any bug or have any suggestion.


Contribution

Fork the repo and submit pull requests.


License

This extension is licensed under the MIT License