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!

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.9 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).


API key

To use the extension, you need an API key from OpenAI or another OpenAI-compatible provider.

How to Set or Change API Key

When you first generate a docstring, a pop-up window will appear requesting you to enter your API key. You can change the API key through the Settings editor (File > Preferences > Settings > Extensions > ChatGPT: Docstring Generator). Or using the Set API key command in the Command Palette (F1).


Switching AI Providers

By default, this extension uses OpenAI API to generate docstrings. However, you can easily switch to other AI services that support OpenAI-compatible APIs.

How to Change AI Provider

  1. Set the Base URL: In the extension settings, locate the baseUrl parameter. You can change this to point to a different OpenAI-compatible API, such as OpenRouter, which offers access to a variety of AI models. For example, to use OpenRouter, set the baseUrl to: https://openrouter.ai/api/v1
  2. Specify the AI Model: To specify which model you want to use, locate the aiModelCustom parameter in the settings. Here, you can define the exact AI model you wish to interact with, depending on the service you're using. For example, if you're using OpenRouter, you might choose from models such as anthropic/claude-3.5-haiku, google/gemini-pro-1.5, or others depending on availability.
  3. Set the API Key: Set your API key for the selected AI service. You can obtain this key from the service website.

Now, the extension will route requests through the selected AI service. Ensure the provider you choose is compatible with OpenAI’s API.


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.baseUrl: The base URL for the OpenAI-compatible API.

    • Default value: "https://api.openai.com/v1"
  • chatgpt-docstrings.aiModel: Which AI language 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.aiModelCustom: If set, overrides the model configured in chatgpt-docstrings.aiModel.

    • Default value: ""
  • chatgpt-docstrings.docstringStyle: Which docstring style 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: AI prompt to generate docstring.

    • Default value: "Generate docstring in {docstring_style} style for python function below:\n{function}"

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

  • chatgpt-docstrings.requestTimeout: The timeout in seconds to use when sending AI API requests.

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

    • Default value: true
    • Available options:
      • true
      • false
  • chatgpt-docstrings.proxy: The URL of the proxy server for AI API requests. The format of the URL is: <protocol>://[<username>:<password>@]<host>:<port>. Where protocol can be: 'http', 'https', 'socks5' or 'socks5h'. The username and password are optional. If not set, will be inherited from the http.proxy setting.

    • Default value: ""
    • Examples:
  • chatgpt-docstrings.proxyAuthorization: The value to send as the Proxy-Authorization HTTP header.

    • Default value: ""
  • chatgpt-docstrings.proxyStrictSSL: "Controls whether the proxy server certificate should be verified against the list of supplied CAs."

    • Default value: false
    • 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