Focus on writing your code, let LLMs write the documentation for you.
Generate comprehensive documentation for your code using OpenAI's powerful language models.
Built with treesitter and OpenAI API
- 📝 Generate documentation comment blocks for all methods in a file
- e.g. Javadoc, JSDoc, Docstring, Rustdoc etc.
- ✍️ Generate inline documentation comments in method bodies
- 🌳 Treesitter integration for accurate code parsing
- 🔄 Support for various OpenAI models (GPT-3.5, GPT-4, etc.)
Note
Documentation will only be added to files without unstaged changes, so nothing is overwritten.
- Python >= 3.9
- OpenAI API Key
Install in an isolated environment with pipx:
pipx install doc-comments-ai
If you are facing issues using pipx you can also install directly from source through PyPI with:
pip install doc-comments-ai
However, it is recommended to use pipx instead to benefit from isolated environments for the dependencies.
You can configure the application using environment variables. Create a .env file in your project root directory based on the provided .env.example:
# OpenAI API Key (Required)
OPENAI_API_KEY=your_api_key_here
# OpenAI Model Selection (Optional, defaults to gpt-3.5-turbo)
# Available options: gpt-3.5-turbo, gpt-4, gpt-3.5-turbo-16k, etc.
OPENAI_MODEL=gpt-3.5-turbo
# OpenAI API Base URL (Optional, for proxy or custom endpoints)
# OPENAI_BASE_URL=https://api.openai.com/v1Or set them directly in your environment:
export OPENAI_API_KEY=your_api_key_here
export OPENAI_MODEL=gpt-4 # Optional
export OPENAI_BASE_URL=your_custom_url # OptionalGenerate documentation for methods in a file:
# Basic usage with default model (gpt-3.5-turbo)
aicomment <RELATIVE_FILE_PATH>
# Use a specific model
aicomment <RELATIVE_FILE_PATH> --model gpt-4
# Add inline comments to method bodies
aicomment <RELATIVE_FILE_PATH> --inline
# Confirm documentation generation for each method
aicomment <RELATIVE_FILE_PATH> --guidedNote
For extensive and descriptive documentation, consider using GPT-4 or GPT-3.5-turbo-16k models which have larger context windows.
- Python
- Typescript
- Javascript
- Java
- Rust
- Kotlin
- Go
- C++
- C
- C#
- Haskell
-
Make sure the rust compiler is installed on your system from here.
pip failed to build package: tiktoken Some possibly relevant errors from pip install: error: subprocess-exited-with-error error: can't find Rust compiler
If you are missing a feature or facing a bug don't hesitate to open an issue or raise a PR. Any kind of contribution is highly appreciated!
