Observed since 21 Oct, 10:32 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
AIDocStringGenerator is an automated tool that utilizes AI technologies like Anthropic and OpenAI GPT-3.5 to generate and manage docstrings in Python code. It streamlines documentation by processing both single files and entire directories, offering customizable settings for docstring verbosity and style. This tool is ideal for enhancing code readability and maintainability in Python projects.
AIDocStringGenerator is an advanced Python tool engineered to streamline the task of creating and updating docstrings in Python source files. Utilizing cutting-edge AI technologies like Anthropic, Google and OpenAI, this application delivers high-quality, context-aware docstrings that significantly enhance code readability and maintainability.
Key Features:
AI-Powered Docstring Generation: Integrates with AI assistant APIs to generate detailed and accurate docstrings for Python classes, methods, and functions.
Flexible File Processing: Capable of handling both individual Python files and entire directories, making it suitable for projects of any scale.
Configurable Operations: Users can customize the behavior through a configuration file (config.json), allowing control over aspects like target paths, verbosity levels, and choice of AI model.
Verbose Output: Offers an optional verbose mode, providing comprehensive logs of the docstring generation process, ideal for debugging and insight into the tool's operations.
Existing Docstring Management: Includes an option to wipe out existing docstrings before generating new ones, ensuring a clean and updated state of documentation.
Large Codebase Handling: Efficiently processes large codebases by splitting the source code into smaller parts, thereby managing API limitations and ensuring thorough coverage.
API Key Management: Supports secure API key integration for accessing AI services, ensuring safe and authorized use of AI technologies.
Use Cases:
The Docstring Generator is particularly useful for:
Developers and Teams: Especially those working on large or complex Python projects who want to maintain high-quality, consistent documentation.
Open Source Contributors: Helps maintain clear and comprehensive documentation in open source projects.
Organizations Emphasizing Code Quality: Organizations that value code readability and maintainability as part of their development standards.
Install the Package: Install it using pip:
pip install AIDocStringGenerator
Initial Configuration:
config_template.json to config.json in the installed package directory."" (empty string).true, existing docstrings in files will be wiped before generating new ones. Default: true.true. Default: true.openai, claude, bard, file). Default: "file"."classTest".true to include subfolders in processing. Default: false.true, the tool saves the bot responses in the "responses" folder. Default: false.5.2.3.79.true, performs a trial run without making actual changes. Default: false.The enabled_botsconfiguration in the DocString Generator specifies AI bots and their models for generating docstrings. Each entry in this list pairs abot(like OpenAI, Anthropic, or Google) with amodel, defining which AI service and model to use. For the "file" bot, model` refers to a specific response file, enabling use of predefined or simulated responses. This configuration allows flexible, multi-bot processing for diverse documentation needs.The config.json file is central to configuring the AIDocStringGenerator. Here's an example structure:
{
"path": "",
"wipe_docstrings": true,
"verbose": true,
"bot": "file",
"model": "classTest",
"enabled_bots": [
{"bot": "google", "model": "bard"},
{"bot": "openai", "model": "gpt-4-1106-preview"},
{"bot": "anthropic", "model": "claude-2.1"}
],
"BARD_API_KEY": "",
"OPENAI_API_KEY": "",
"CLAUDE_API_KEY": "",
"include_subfolders": false,
"keep_responses": false,
"ignore": "",
"class_docstrings_verbosity_level": 5,
"function_docstrings_verbosity_level": 2,
"example_verbosity_level": 3,
"max_line_length": 79,
"dry_run": false
}
To securely manage API keys:
Create a .env file in the root folder.
Add your API keys in the following format:
CLAUDE_API_KEY=my_key
OPENAI_API_KEY=my_key
BARD_API_KEY=my_key
This ensures that your keys are stored securely and not exposed in your version control system.
The AIDocStringGenerator automatically handles response errors. For instance, if the response JSON format is invalid, the tool will re-query the chatbot. This also applies to invalid example code, ensuring a smooth and error-resilient operation.
An example of the tool in action:
Before:
class Calculator:
def add(self, a, b):
return a + b
def subtract(self, a, b):
return a - b
def multiply(self, a, b):
return a * b
def divide(self, a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
After:
class Calculator:
"""A simple class that performs basic arithmetic operations."""
def add(self, a, b):
"""Adds two numbers together and returns the result."""
return a + b
def subtract(self, a, b):
"""Subtracts two numbers and returns the result."""
return a - b
def multiply(self, a, b):
"""Multiplies two numbers together and returns the result."""
return a * b
def divide(self, a, b):
"""Divides two numbers and returns the result. Raises a ValueError if the divisor is zero."""
if b == 0:
raise ValueError('Cannot divide by zero')
return a / b
def example_function_Calculator(self):
calculator = Calculator()
result = calculator.add(1, 2)
print(result) # Prints 3
This example demonstrates how AIDocStringGenerator can transform a simple Python class by adding informative and well-structured docstrings, greatly enhancing code readability and documentation.
Based on the BOTS dictionary provided, the possible combinations of bot and model configurations are as follows:
OpenAI Bots:
"openai" bot with "gpt-3.5-turbo-1106" model"openai" bot with "gpt-4-1106-preview" modelAnthropic Bots:
"anthropic" bot with "claude-2.1" modelGoogle Bots:
"google" bot with "bard" modelFile Bots:
"file" bot with any custom module name as the model. For example, "classTest".When using the "file" bot, the model parameter has a unique purpose. Instead of representing an AI model, it specifies the name of a module, which in turn corresponds to a response file. Here's how it works:
model name, the DocString Generator will look for a file with a specific naming pattern.model is set to "classTest", the tool will search for a file named "classTest.response.json" for the initial attempt."classTest.response2.json", "classTest.response3.json", and so on."classTest.example.json".This approach allows for a high degree of flexibility and control, especially for testing or simulating responses without directly using an AI service. It's ideal for scenarios where response data is predefined or needs to be consistent across multiple runs.
"file" bot configuration is particularly useful for scenarios where you have a set of predefined responses or wish to simulate the behavior of the tool without making actual API calls to AI services.Command Line Overrides:
Command line arguments allow you to override settings in config.json.
Example command:
AIDocStringGenerator --path "/path/to/source" --verbose --wipe_docstrings --bot "claude" --include_subfolders --verbosity_level "5"
Verbosity Levels:
To control the level of detail in the generated docstrings and examples, you can use the following verbosity levels:
Function and Class Docstrings Verbosity Levels:
Example Verbosity Levels:
The AI Docstring Generator can process either a single Python file or an entire directory containing multiple files. You have two options for providing processing instructions:
To run the tool with command-line arguments, use the following format:
AIDocStringGenerator --path "/path/to/python/files" --verbose
This command processes Python files located at the specified path, with verbose output enabled.
If you start the program without providing command-line arguments, it will automatically look for a configuration file named config.json in the current working directory. This file allows you to specify the processing parameters in a structured format.
The AI Docstring Generator represents a significant advancement in automating the critical task of software documentation. Its key benefits include:
By effectively utilizing this tool, you can maintain high-quality, consistent, and up-to-date documentation for your Python codebases, promoting better code understanding, maintainability, and collaboration.
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0 | 2 Jan 2024 | 39 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 21 Oct, 10:32 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:b580d09662a01aaf1b200150401812b62d3f220105d88110dbd0c15c2583a136