Automatically generate Python docstrings using ChatGPT.
Notice!
- To use the extension, you need an API key from OpenAI or another OpenAI-compatible provider.
- This is a pre-release version of the extension. In case of issues, please keep feedback on github.
- Installation
- Requirements
- Usage
- API key
- Switching AI Providers
- Settings
- Telemetry
- Change Log
- Feedback
- Contribution
- License
Install it from Visual Studio Marketplace or download and install .vsix file from Releases.
- VSCode 1.75.0 or greater
- Python 3.9 or greater
Type """
and select Generate Docstring (ChatGPT)
from the completion items.
Right click in the Text Editor area and select Generate Docstring (ChatGPT)
.
Open the Command Palette (F1), type docstring
and select Generate Docstring (ChatGPT)
.
Use the following keyboard shortcut:
- Windows/Linux:
Ctrl+Alt+D
- Mac:
Cmd+Opt+D
You can change the default keyboard shortcut by Keyboard Shortcuts editor (File > Preferences > Keyboard Shortcuts).
To use the extension, you need an API key from OpenAI or another OpenAI-compatible provider.
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).
By default, this extension uses OpenAI API to generate docstrings. However, you can easily switch to other AI services that support OpenAI-compatible APIs.
- 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 thebaseUrl
to:https://openrouter.ai/api/v1
- 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 asanthropic/claude-3.5-haiku
,google/gemini-pro-1.5
, or others depending on availability. - 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.
-
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
"
- Default value: "
-
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 inchatgpt-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 parameterchatgpt-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>
. Whereprotocol
can be: 'http', 'https', 'socks5' or 'socks5h'. The username and password are optional. If not set, will be inherited from thehttp.proxy
setting.- Default value: ""
- Examples:
http://proxy.com:80
http://127.0.0.1:80
socks5://user:[email protected]:1080
-
chatgpt-docstrings.proxyAuthorization
: The value to send as theProxy-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
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.
See Change Log here
Submit the issues if you find any bug or have any suggestion.
Fork the repo and submit pull requests.
This extension is licensed under the MIT License